package tokenize_test import ( "fmt" "strings" "testing" "git.makaay.nl/mauricem/go-parsekit/tokenize" ) func ExampleToken() { t0 := tokenize.Token{ Runes: []rune("10.1.2.3"), } t1 := tokenize.Token{ Runes: []rune("two hundred and twenty four"), Type: "Number", Value: 224, } const TName = 1 t2 := tokenize.Token{ Runes: []rune("John"), Type: TName, } t3 := tokenize.Token{ Runes: []rune("The answer"), Value: 42, } fmt.Printf("%s\n%s\n%s\n%s\n", t0, t1, t2, t3) // Output: // ("10.1.2.3") // Number("two hundred and twenty four", value = (int)224) // 1("John") // ("The answer", value = (int)42) } func TestSetResult_AcceptsVariousTypesAsInput(t *testing.T) { i := tokenize.NewAPI(strings.NewReader("Testing")) i.Result().SetRunes("string") AssertEqual(t, "string", string(i.Result().String()), "i.Result() with string input") i.Result().SetRunes([]rune("rune slice")) AssertEqual(t, "rune slice", string(i.Result().String()), "i.Result() with rune slice input") i.Result().SetRunes('X') AssertEqual(t, "X", string(i.Result().String()), "i.Result() with rune input") } func TestSetResult_PanicsOnUnhandledInput(t *testing.T) { AssertPanic(t, PanicT{ Function: func() { i := tokenize.NewAPI(strings.NewReader("Testing")) i.Result().SetRunes(1234567) }, Regexp: true, Expect: `tokenize\.Result\.SetRunes\(\): unsupported type 'int' used at /.*/result_test.go:\d+`, }) }