mirror of
https://github.com/pikami/cosmium.git
synced 2026-09-29 22:54:17 +01:00
Compare commits
2
Commits
1.26.x
..
c78842726b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c78842726b | ||
|
|
90de21c7b0 |
@@ -134,6 +134,34 @@ func Test_Documents(t *testing.T) {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("Should query document with single-quoted string literal", func(t *testing.T) {
|
||||||
|
testCosmosQuery(t, collectionClient,
|
||||||
|
`select c.id
|
||||||
|
FROM c
|
||||||
|
WHERE c.id='67890'
|
||||||
|
ORDER BY c.id`,
|
||||||
|
nil,
|
||||||
|
[]interface{}{
|
||||||
|
map[string]interface{}{"id": "67890"},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Should query document with escaped single-quoted string literal", func(t *testing.T) {
|
||||||
|
ts.DataStore.CreateDocument(testDatabaseName, testCollectionName, map[string]interface{}{"id": "apostrophe-doc", "pk": "ap", "name": "it's"})
|
||||||
|
|
||||||
|
testCosmosQuery(t, collectionClient,
|
||||||
|
`select c.id
|
||||||
|
FROM c
|
||||||
|
WHERE c.name='it\'s'
|
||||||
|
ORDER BY c.id`,
|
||||||
|
nil,
|
||||||
|
[]interface{}{
|
||||||
|
map[string]interface{}{"id": "apostrophe-doc"},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("Should query document with query parameters", func(t *testing.T) {
|
t.Run("Should query document with query parameters", func(t *testing.T) {
|
||||||
testCosmosQuery(t, collectionClient,
|
testCosmosQuery(t, collectionClient,
|
||||||
`select c.id
|
`select c.id
|
||||||
|
|||||||
+1508
-1335
File diff suppressed because it is too large
Load Diff
@@ -509,6 +509,8 @@ IntegerLiteral <- number:Integer {
|
|||||||
}
|
}
|
||||||
StringLiteral <- "\"" chars:StringCharacter* "\"" {
|
StringLiteral <- "\"" chars:StringCharacter* "\"" {
|
||||||
return parsers.Constant{Type: parsers.ConstantTypeString,Value: joinStrings(chars.([]interface{}))}, nil
|
return parsers.Constant{Type: parsers.ConstantTypeString,Value: joinStrings(chars.([]interface{}))}, nil
|
||||||
|
} / "'" chars:SingleQuotedStringCharacter* "'" {
|
||||||
|
return parsers.Constant{Type: parsers.ConstantTypeString,Value: joinStrings(chars.([]interface{}))}, nil
|
||||||
}
|
}
|
||||||
FloatLiteral <- [0-9]+"."[0-9]+ {
|
FloatLiteral <- [0-9]+"."[0-9]+ {
|
||||||
floatValue, _ := strconv.ParseFloat(string(c.text), 64)
|
floatValue, _ := strconv.ParseFloat(string(c.text), 64)
|
||||||
@@ -869,11 +871,14 @@ Integer <- [0-9]+ {
|
|||||||
StringCharacter <- !('"' / "\\") . { return string(c.text), nil }
|
StringCharacter <- !('"' / "\\") . { return string(c.text), nil }
|
||||||
/ "\\" seq:EscapeSequenceCharacter { return seq, nil }
|
/ "\\" seq:EscapeSequenceCharacter { return seq, nil }
|
||||||
|
|
||||||
|
SingleQuotedStringCharacter <- !("'" / "\\") . { return string(c.text), nil }
|
||||||
|
/ "\\" seq:EscapeSequenceCharacter { return seq, nil }
|
||||||
|
|
||||||
EscapeSequenceCharacter <- char:EscapeCharacter
|
EscapeSequenceCharacter <- char:EscapeCharacter
|
||||||
|
|
||||||
EscapeCharacter <- "'"
|
EscapeCharacter <- "'" { return "'", nil }
|
||||||
/ '"'
|
/ '"' { return "\"", nil }
|
||||||
/ "\\"
|
/ "\\" { return "\\", nil }
|
||||||
/ "b" { return "\b", nil }
|
/ "b" { return "\b", nil }
|
||||||
/ "f" { return "\f", nil }
|
/ "f" { return "\f", nil }
|
||||||
/ "n" { return "\n", nil }
|
/ "n" { return "\n", nil }
|
||||||
|
|||||||
@@ -149,6 +149,32 @@ func Test_Parse_Were(t *testing.T) {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("Should correctly parse single-quoted string literals", func(t *testing.T) {
|
||||||
|
testQueryParse(
|
||||||
|
t,
|
||||||
|
`SELECT c.id FROM c WHERE c.id = '12345' AND c.string = 'it\'s'`,
|
||||||
|
parsers.SelectStmt{
|
||||||
|
SelectItems: []parsers.SelectItem{{Path: []string{"c", "id"}}},
|
||||||
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
|
Filters: parsers.LogicalExpression{
|
||||||
|
Operation: parsers.LogicalExpressionTypeAnd,
|
||||||
|
Expressions: []interface{}{
|
||||||
|
parsers.ComparisonExpression{
|
||||||
|
Operation: "=",
|
||||||
|
Left: parsers.SelectItem{Path: []string{"c", "id"}},
|
||||||
|
Right: testutils.SelectItem_Constant_String("12345"),
|
||||||
|
},
|
||||||
|
parsers.ComparisonExpression{
|
||||||
|
Operation: "=",
|
||||||
|
Left: parsers.SelectItem{Path: []string{"c", "string"}},
|
||||||
|
Right: testutils.SelectItem_Constant_String("it's"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("Should correctly parse NOT conditions", func(t *testing.T) {
|
t.Run("Should correctly parse NOT conditions", func(t *testing.T) {
|
||||||
testQueryParse(
|
testQueryParse(
|
||||||
t,
|
t,
|
||||||
|
|||||||
Reference in New Issue
Block a user