|
| 1 | +package test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + lqp "github.com/RelationalAI/logical-query-protocol/sdks/go/src" |
| 7 | +) |
| 8 | + |
| 9 | +// TestSymbolLexerRegex verifies that the SYMBOL regex treats hyphen as a literal |
| 10 | +// character and does not accidentally include characters like $, %, etc. |
| 11 | +func TestSymbolLexerRegex(t *testing.T) { |
| 12 | + t.Run("hyphenated symbol", func(t *testing.T) { |
| 13 | + // A hyphenated relation name should parse without error. |
| 14 | + input := `(fragment :test (def :my-rel ([x::INT] (relatom :my-rel x))))` |
| 15 | + result, _, err := lqp.ParseFragment(input) |
| 16 | + if err != nil { |
| 17 | + t.Fatalf("Failed to parse hyphenated symbol: %v", err) |
| 18 | + } |
| 19 | + if result == nil { |
| 20 | + t.Fatal("ParseFragment returned nil") |
| 21 | + } |
| 22 | + }) |
| 23 | + |
| 24 | + t.Run("symbol with hash and slash", func(t *testing.T) { |
| 25 | + input := `(fragment :test (def :base/#output ([x::INT] (relatom :base/#output x))))` |
| 26 | + result, _, err := lqp.ParseFragment(input) |
| 27 | + if err != nil { |
| 28 | + t.Fatalf("Failed to parse symbol with hash and slash: %v", err) |
| 29 | + } |
| 30 | + if result == nil { |
| 31 | + t.Fatal("ParseFragment returned nil") |
| 32 | + } |
| 33 | + }) |
| 34 | + |
| 35 | + t.Run("dollar terminates symbol", func(t *testing.T) { |
| 36 | + // '$' is not a valid SYMBOL character, so this should fail to parse. |
| 37 | + input := `(fragment :test (def :foo$bar ([x::INT] (relatom :foo$bar x))))` |
| 38 | + _, _, err := lqp.ParseFragment(input) |
| 39 | + if err == nil { |
| 40 | + t.Error("Expected parse error for symbol containing '$'") |
| 41 | + } |
| 42 | + }) |
| 43 | +} |
0 commit comments