use of java.util.NoSuchElementException in project robovm by robovm.
the class ScannerTest method test_nextBoolean.
/**
* @throws IOException
* @tests java.util.Scanner#nextBoolean()
*/
public void test_nextBoolean() throws IOException {
// case insensitive
s = new Scanner("TRue");
assertTrue(s.nextBoolean());
s = new Scanner("tRue false");
assertTrue(s.nextBoolean());
assertFalse(s.nextBoolean());
try {
s.nextBoolean();
fail();
} catch (NoSuchElementException expected) {
}
s = new Scanner("true1");
try {
s.nextBoolean();
fail();
} catch (InputMismatchException expected) {
}
try {
s = new Scanner("");
s.nextBoolean();
fail();
} catch (NoSuchElementException expected) {
}
// test socket inputStream
os.write("true false".getBytes());
serverSocket.close();
s = new Scanner(client);
assertTrue(s.nextBoolean());
assertFalse(s.nextBoolean());
// ues '*' as delimiter
s = new Scanner("true**false").useDelimiter("\\*");
assertTrue(s.nextBoolean());
try {
s.nextBoolean();
fail();
} catch (NoSuchElementException expected) {
}
s = new Scanner("false( )").useDelimiter("\\( \\)");
assertFalse(s.nextBoolean());
}
use of java.util.NoSuchElementException in project robovm by robovm.
the class ScannerTest method test_nextByteI.
/**
* @throws IOException
* @tests java.util.Scanner#nextByte(int)
*/
public void test_nextByteI() throws IOException {
s = new Scanner("123 126");
assertEquals(123, s.nextByte(10));
assertEquals(126, s.nextByte(10));
try {
s.nextByte(10);
fail();
} catch (NoSuchElementException expected) {
}
// If the radix is different from 10
s = new Scanner("123 126");
assertEquals(38, s.nextByte(5));
try {
s.nextByte(5);
fail();
} catch (InputMismatchException expected) {
}
// If the number is out of range
s = new Scanner("1234");
try {
s.nextByte(10);
fail();
} catch (InputMismatchException expected) {
}
/*
* The input string has Arabic-Indic digits.
*/
s = new Scanner("1٠2 12٦");
assertEquals(102, s.nextByte(10));
try {
s.nextByte(5);
fail();
} catch (InputMismatchException expected) {
}
assertEquals(126, s.nextByte(10));
s = new Scanner("012");
assertEquals(12, s.nextByte(10));
s = new Scanner("E");
assertEquals(14, s.nextByte(16));
/*
* There are 3 types of zero digit in all locales, '0' '०' '๐'
* respectively, but they are not differentiated.
*/
s = new Scanner("100");
s.useLocale(Locale.CHINESE);
assertEquals(100, s.nextByte(10));
s = new Scanner("1००");
s.useLocale(Locale.CHINESE);
assertEquals(100, s.nextByte(10));
s = new Scanner("1๐๐");
s.useLocale(Locale.CHINESE);
assertEquals(100, s.nextByte(10));
s = new Scanner("-123");
s.useLocale(new Locale("ar", "AE"));
assertEquals(-123, s.nextByte(10));
s = new Scanner("-123");
s.useLocale(new Locale("mk", "MK"));
assertEquals(-123, s.nextByte(10));
}
use of java.util.NoSuchElementException in project robovm by robovm.
the class ScannerTest method test_match.
/**
* @tests java.util.Scanner#match()
*/
public void test_match() {
MatchResult result;
s = new Scanner("1 2 ");
try {
s.match();
fail();
} catch (IllegalStateException expected) {
}
assertEquals("1", s.next());
assertEquals("2", s.next());
result = s.match();
assertEquals(2, result.start());
assertEquals(3, result.end());
assertEquals(2, result.start(0));
assertEquals(3, result.end(0));
assertEquals("2", result.group());
assertEquals("2", result.group(0));
assertEquals(0, result.groupCount());
try {
result.start(1);
fail();
} catch (IndexOutOfBoundsException expected) {
}
try {
s.next();
fail();
} catch (NoSuchElementException expected) {
}
try {
s.match();
fail();
} catch (IllegalStateException expected) {
}
s = new Scanner("True faLse");
try {
s.match();
fail();
} catch (IllegalStateException expected) {
}
assertTrue(s.nextBoolean());
result = s.match();
assertEquals(0, result.start());
assertEquals(4, result.end());
assertEquals(0, result.start(0));
assertEquals(4, result.end(0));
assertEquals("True", result.group());
assertEquals(0, result.groupCount());
assertFalse(s.nextBoolean());
try {
s.nextBoolean();
fail();
} catch (NoSuchElementException expected) {
}
try {
s.match();
fail();
} catch (IllegalStateException expected) {
}
s = new Scanner("True faLse");
assertTrue(s.nextBoolean());
result = s.match();
assertEquals(0, result.start());
assertEquals(4, result.end());
assertEquals(0, result.start(0));
assertEquals(4, result.end(0));
assertEquals("True", result.group());
assertEquals(0, result.groupCount());
s.close();
try {
s.nextBoolean();
fail();
} catch (IllegalStateException expected) {
}
result = s.match();
assertEquals(0, result.start());
assertEquals(4, result.end());
assertEquals(0, result.start(0));
assertEquals(4, result.end(0));
assertEquals("True", result.group());
assertEquals(0, result.groupCount());
s = new Scanner("True fase");
assertTrue(s.nextBoolean());
assertEquals(0, result.groupCount());
try {
s.nextBoolean();
fail();
} catch (InputMismatchException expected) {
}
try {
s.match();
fail();
} catch (IllegalStateException expected) {
}
s = new Scanner("True fase");
assertTrue(s.nextBoolean());
try {
s.next((Pattern) null);
fail();
} catch (NullPointerException expected) {
}
result = s.match();
assertEquals(0, result.start());
assertEquals(4, result.end());
assertEquals(0, result.start(0));
assertEquals(4, result.end(0));
assertEquals("True", result.group());
assertEquals(0, result.groupCount());
}
use of java.util.NoSuchElementException in project robovm by robovm.
the class ScannerTest method test_nextFloat.
/**
* @throws IOException
* @tests java.util.Scanner#nextFloat()
*/
public void test_nextFloat() throws IOException {
s = new Scanner("123 45٦. 123.4 .123 ");
s.useLocale(Locale.ENGLISH);
assertEquals((float) 123.0, s.nextFloat());
assertEquals((float) 456.0, s.nextFloat());
assertEquals((float) 123.4, s.nextFloat());
assertEquals((float) 0.123, s.nextFloat());
try {
s.nextFloat();
fail();
} catch (NoSuchElementException expected) {
}
s = new Scanner("+123.4 -456.7 123,456.789 0.1٢3,4");
s.useLocale(Locale.ENGLISH);
assertEquals((float) 123.4, s.nextFloat());
assertEquals((float) -456.7, s.nextFloat());
assertEquals((float) 123456.789, s.nextFloat());
try {
s.nextFloat();
fail();
} catch (InputMismatchException expected) {
}
// Scientific notation
s = new Scanner("+123.4E10 -456.7e+12 123,456.789E-10");
s.useLocale(Locale.ENGLISH);
assertEquals((float) 1.234E12, s.nextFloat());
assertEquals((float) -4.567E14, s.nextFloat());
assertEquals((float) 1.23456789E-5, s.nextFloat());
s = new Scanner("NaN Infinity -Infinity");
assertEquals(Float.NaN, s.nextFloat());
assertEquals(Float.POSITIVE_INFINITY, s.nextFloat());
assertEquals(Float.NEGATIVE_INFINITY, s.nextFloat());
String str = String.valueOf(Float.MAX_VALUE * 2);
s = new Scanner(str);
assertEquals(Float.POSITIVE_INFINITY, s.nextFloat());
/*
* Different locale can only recognize corresponding locale sensitive
* string. ',' is used in many locales as group separator.
*/
s = new Scanner("23,456 23,456");
s.useLocale(Locale.ENGLISH);
assertEquals((float) 23456.0, s.nextFloat());
s.useLocale(Locale.GERMANY);
assertEquals((float) 23.456, s.nextFloat());
s = new Scanner("23.456 23.456");
s.useLocale(Locale.ENGLISH);
assertEquals((float) 23.456, s.nextFloat());
s.useLocale(Locale.GERMANY);
assertEquals((float) 23456.0, s.nextFloat());
s = new Scanner("23,456.7 23.456,7");
s.useLocale(Locale.ENGLISH);
assertEquals((float) 23456.7, s.nextFloat());
s.useLocale(Locale.GERMANY);
assertEquals((float) 23456.7, s.nextFloat());
s = new Scanner("-123.4 123.4- -123.4-");
s.useLocale(new Locale("ar", "AE"));
// assertEquals((float)-123.4, s.nextFloat());
try {
s.nextFloat();
fail();
} catch (InputMismatchException expected) {
}
s = new Scanner("123- -123");
s.useLocale(new Locale("mk", "MK"));
try {
s.nextFloat();
fail();
} catch (InputMismatchException expected) {
}
// Skip the un-recognizable token 123-.
assertEquals("123-", s.next());
assertEquals((float) -123.0, s.nextFloat());
}
use of java.util.NoSuchElementException in project robovm by robovm.
the class ScannerTest method test_nextBigDecimal.
/**
* @throws IOException
* @tests java.util.Scanner#nextBigDecimal()
*/
public void test_nextBigDecimal() throws IOException {
s = new Scanner("123 45٦. 123.4 .123 ");
s.useLocale(Locale.ENGLISH);
assertEquals(new BigDecimal("123"), s.nextBigDecimal());
assertEquals(new BigDecimal("456"), s.nextBigDecimal());
assertEquals(new BigDecimal("123.4"), s.nextBigDecimal());
assertEquals(new BigDecimal("0.123"), s.nextBigDecimal());
try {
s.nextBigDecimal();
fail();
} catch (NoSuchElementException expected) {
}
s = new Scanner("+123.4 -456.7 123,456.789 0.1٢3,4");
s.useLocale(Locale.ENGLISH);
assertEquals(new BigDecimal("123.4"), s.nextBigDecimal());
assertEquals(new BigDecimal("-456.7"), s.nextBigDecimal());
assertEquals(new BigDecimal("123456.789"), s.nextBigDecimal());
try {
s.nextBigDecimal();
fail();
} catch (InputMismatchException expected) {
}
// Scientific notation
s = new Scanner("+123.4E10 -456.7e+12 123,456.789E-10");
s.useLocale(Locale.ENGLISH);
assertEquals(new BigDecimal("1.234E12"), s.nextBigDecimal());
assertEquals(new BigDecimal("-4.567E14"), s.nextBigDecimal());
assertEquals(new BigDecimal("1.23456789E-5"), s.nextBigDecimal());
s = new Scanner("NaN");
try {
s.nextBigDecimal();
fail();
} catch (InputMismatchException expected) {
}
/*
* Different locale can only recognize corresponding locale sensitive
* string. ',' is used in many locales as group separator.
*/
s = new Scanner("23,456 23,456");
s.useLocale(Locale.ENGLISH);
assertEquals(new BigDecimal("23456"), s.nextBigDecimal());
s.useLocale(Locale.GERMANY);
assertEquals(new BigDecimal("23.456"), s.nextBigDecimal());
s = new Scanner("23.456 23.456");
s.useLocale(Locale.ENGLISH);
assertEquals(new BigDecimal("23.456"), s.nextBigDecimal());
s.useLocale(Locale.GERMANY);
assertEquals(new BigDecimal("23456"), s.nextBigDecimal());
s = new Scanner("23,456.7");
s.useLocale(Locale.ENGLISH);
assertEquals(new BigDecimal("23456.7"), s.nextBigDecimal());
s = new Scanner("-123.4");
s.useLocale(Locale.ENGLISH);
assertEquals(new BigDecimal("-123.4"), s.nextBigDecimal());
}
Aggregations