コード例 #1
0
ファイル: string_test.go プロジェクト: mm0205/gjson
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)
	}
}
コード例 #2
0
ファイル: multicharacter_test.go プロジェクト: mm0205/gjson
func TestMultiCharacterScannerRuneOfToken(t *testing.T) {
	testCaseList := []testCaseForTestMultiCharacterScannerRuneOfToken{
		{data: " null ", tokenKind: token.KindNull, expected: 'n'},
		{data: " true ", tokenKind: token.KindTrue, expected: 't'},
		{data: " false ", tokenKind: token.KindFalse, expected: 'f'},
	}
	for testIndex, testCase := range testCaseList {
		stringReader := strings.NewReader(testCase.data)
		jsonScanner := scanner.NewJSONScanner(stringReader)
		scanner := tokenscanner.NewMultiCharacterScanner(testCase.tokenKind, jsonScanner).(*tokenscanner.MultiCharacterScanner)

		actual := scanner.RuneOfToken()
		expected := testCase.expected

		if actual != expected {
			t.Errorf("testCase[%d] expected=%#v, actual=%#v", testIndex, string(expected), string(actual))
		}
	}
}