package com.alibaba.fastjson.parser; import com.alibaba.fastjson.JSONException; import org.junit.Assert; import org.junit.Test; public class JSONScannerTest2 { @Test public void stringUtf8BomTest() throws Throwable { JSONScanner scanner = new JSONScanner("\uFEFF,"); // After construction the UTF-8 BOM should be safely skipped scanner.nextToken(); Assert.assertEquals(JSONToken.COMMA, scanner.token()); } @Test public void stringHasSpecialTest() throws Throwable { JSONScanner scanner = new JSONScanner("\"\\b\\n\\t\\\"\\uABED\""); // After construction the UTF-8 BOM should be safely skipped scanner.nextToken(); Assert.assertEquals(JSONToken.LITERAL_STRING, scanner.token()); Assert.assertEquals("\b\n\t\"\uABED", scanner.stringVal()); } @Test public void stringWithIso8601Date() throws Throwable { JSONScanner scanner = new JSONScanner("2012-04-23T18:25:43.511Z"); // After construction the UTF-8 BOM should be safely skipped Assert.assertTrue(scanner.scanISO8601DateIfMatch()); } @Test public void scanSingleComment() throws Throwable { JSONScanner scanner = new JSONScanner("//dsajfklsjfk"); // After construction the UTF-8 BOM should be safely skipped scanner.nextToken(); Assert.assertTrue(scanner.isEOF()); } @Test public void scanMultiComment() throws Throwable { JSONScanner scanner = new JSONScanner("/*dsajfklsjfk*/"); // After construction the UTF-8 BOM should be safely skipped scanner.nextToken(); Assert.assertTrue(scanner.isEOF()); } @Test public void scannerSkipWhitespace() throws Throwable { JSONScanner scanner = new JSONScanner("\n\t\t \r\b\f232"); scanner.nextToken(); Assert.assertEquals(JSONToken.LITERAL_INT, scanner.token()); Assert.assertEquals(232, scanner.intValue()); } @Test public void inputTokenTest_Null() throws Throwable { JSONScanner scanner = new JSONScanner("null"); // After construction the UTF-8 BOM should be safely skipped scanner.nextToken(); Assert.assertEquals(JSONToken.NULL, scanner.token()); } @Test public void inputTokenTest_Undefined() throws Throwable { JSONScanner scanner = new JSONScanner("undefined"); // After construction the UTF-8 BOM should be safely skipped scanner.nextToken(); Assert.assertEquals(JSONToken.UNDEFINED, scanner.token()); } @Test public void inputTokenTest_Undefined() throws Throwable { JSONScanner scanner = new JSONScanner("undefined"); // After construction the UTF-8 BOM should be safely skipped scanner.nextToken(); Assert.assertEquals(JSONToken.UNDEFINED, scanner.token()); } @Test public void inputTokenTest_ExplPosInt() throws Throwable { JSONScanner scanner = new JSONScanner("+7531"); // explicit positive with sign scanner.nextToken(); Assert.assertEquals(JSONToken.LITERAL_INT, scanner.token()); Assert.assertEquals(7531, scanner.intValue()); } }