package jmespath import ( "fmt" "testing" "github.com/stretchr/testify/assert" ) var lexingTests = []struct { expression string expected []token }{ {"*", []token{{tStar, "*", 0, 1}}}, {".", []token{{tDot, ".", 0, 1}}}, {"[?", []token{{tFilter, "[?", 0, 2}}}, {"[]", []token{{tFlatten, "[]", 0, 2}}}, {"(", []token{{tLparen, "(", 0, 1}}}, {")", []token{{tRparen, ")", 0, 1}}}, {"[", []token{{tLbracket, "[", 0, 1}}}, {"]", []token{{tRbracket, "]", 0, 1}}}, {"{", []token{{tLbrace, "{", 0, 1}}}, {"}", []token{{tRbrace, "}", 0, 1}}}, {"||", []token{{tOr, "||", 0, 2}}}, {"|", []token{{tPipe, "|", 0, 1}}}, {"29", []token{{tNumber, "29", 0, 2}}}, {"2", []token{{tNumber, "2", 0, 1}}}, {"0", []token{{tNumber, "0", 0, 1}}}, {"-20", []token{{tNumber, "-20", 0, 3}}}, {"foo", []token{{tUnquotedIdentifier, "foo", 0, 3}}}, {`"bar"`, []token{{tQuotedIdentifier, "bar", 0, 3}}}, // Escaping the delimiter {`"bar\"baz"`, []token{{tQuotedIdentifier, `bar"baz`, 0, 7}}}, {",", []token{{tComma, ",", 0, 1}}}, {":", []token{{tColon, ":", 0, 1}}}, {"<", []token{{tLT, "<", 0, 1}}}, {"<=", []token{{tLTE, "<=", 0, 2}}}, {">", []token{{tGT, ">", 0, 1}}}, {">=", []token{{tGTE, ">=", 0, 2}}}, {"==", []token{{tEQ, "==", 0, 2}}}, {"!=", []token{{tNE, "!=", 0, 2}}}, {"`[0, 1, 2]`", []token{{tJSONLiteral, "[0, 1, 2]", 1, 9}}}, {"'foo'", []token{{tStringLiteral, "foo", 1, 3}}}, {"'a'", []token{{tStringLiteral, "a", 1, 1}}}, {`'foo\'bar'`, []token{{tStringLiteral, "foo'bar", 1, 7}}}, {"@", []token{{tCurrent, "@", 0, 1}}}, {"&", []token{{tExpref, "&", 0, 1}}}, // Quoted identifier unicode escape sequences {`"\u2713"`, []token{{tQuotedIdentifier, "✓", 0, 3}}}, {`"\\"`, []token{{tQuotedIdentifier, `\`, 0, 1}}}, {"`\"foo\"`", []token{{tJSONLiteral, "\"foo\"", 1, 5}}}, // Combinations of tokens. {"foo.bar", []token{ {tUnquotedIdentifier, "foo", 0, 3}, {tDot, ".", 3, 1}, {tUnquotedIdentifier, "bar", 4, 3}, }}, {"foo[0]", []token{ {tUnquotedIdentifier, "foo", 0, 3}, {tLbracket, "[", 3, 1}, {tNumber, "0", 4, 1}, {tRbracket, "]", 5, 1}, }}, {"foo[?a