func TestStringScanner1(t *testing.T) { testData := ` "teststring" ` reader := strings.NewReader(testData) jsonScanner := scanner.NewJSONScanner(reader) scanner := tokenscanner.NewStringScanner(jsonScanner).(*tokenscanner.StringScanner) if !scanner.CanProcess() { t.Error("testData can process") } if scanner.RuneOfToken() != '"' { t.Error("StringScanner.RunOfToken must be '\"'") } if !scanner.CanProcessRune('"') { t.Error("StringScanner.CanProcessRune can process rune '\"'") } expectedToken := token.NewToken(token.KindString, "teststring") token, err := scanner.Scan() if err != nil { t.Error(err) } if !expectedToken.IsEqualTo(token) { t.Errorf("expected=%#v, actual=%#v", expectedToken, token) } }
func TestMultiCharacterScannerCanProcessRune(t *testing.T) { testCaseList := []testCaseForTestMultiCharacterScannerCanProcessRune{ {data: " null ", test: 'n', tokenKind: token.KindNull, expected: true}, {data: " true ", test: 't', tokenKind: token.KindTrue, expected: true}, {data: " false ", test: 'f', tokenKind: token.KindFalse, expected: true}, {data: " false ", test: '.', tokenKind: token.KindFalse, expected: false}, {data: " false ", test: '-', tokenKind: token.KindTrue, expected: false}, {data: " false ", test: 't', tokenKind: token.KindNull, expected: false}, } for testIndex, testCase := range testCaseList { stringReader := strings.NewReader(testCase.data) jsonScanner := scanner.NewJSONScanner(stringReader) scanner := tokenscanner.NewMultiCharacterScanner(testCase.tokenKind, jsonScanner).(*tokenscanner.MultiCharacterScanner) actual := scanner.CanProcessRune(testCase.test) expected := testCase.expected if actual != expected { t.Errorf("testCase[%d] expected=%#v, actual=%#v", testIndex, expected, actual) } } }