| 7 | ) |
| 8 | |
| 9 | func TestSplitSQL(t *testing.T) { |
| 10 | testCases := []struct { |
| 11 | description string |
| 12 | statement string |
| 13 | wantCount int |
| 14 | wantTexts []string |
| 15 | wantNil bool |
| 16 | }{ |
| 17 | { |
| 18 | description: "single statement", |
| 19 | statement: `db.users.find({})`, |
| 20 | wantCount: 1, |
| 21 | wantTexts: []string{`db.users.find({})`}, |
| 22 | }, |
| 23 | { |
| 24 | description: "two statements with semicolons", |
| 25 | statement: `db.users.find({});db.products.find({})`, |
| 26 | wantCount: 2, |
| 27 | wantTexts: []string{`db.users.find({});`, `db.products.find({})`}, |
| 28 | }, |
| 29 | { |
| 30 | description: "two statements with newlines", |
| 31 | statement: "db.users.find({})\ndb.products.find({})", |
| 32 | wantCount: 2, |
| 33 | wantTexts: []string{`db.users.find({})`, `db.products.find({})`}, |
| 34 | }, |
| 35 | { |
| 36 | description: "two statements with semicolon and newline", |
| 37 | statement: "db.users.find({});\ndb.products.insertOne({name: \"test\"})", |
| 38 | wantCount: 2, |
| 39 | wantTexts: []string{"db.users.find({});", `db.products.insertOne({name: "test"})`}, |
| 40 | }, |
| 41 | { |
| 42 | description: "three statements mixed separators", |
| 43 | statement: "show dbs;\ndb.users.find({})\ndb.products.drop()", |
| 44 | wantCount: 3, |
| 45 | wantTexts: []string{"show dbs;", "db.users.find({})", "db.products.drop()"}, |
| 46 | }, |
| 47 | { |
| 48 | description: "single statement with trailing semicolon", |
| 49 | statement: `db.users.find({});`, |
| 50 | wantCount: 1, |
| 51 | wantTexts: []string{`db.users.find({});`}, |
| 52 | }, |
| 53 | { |
| 54 | description: "empty input", |
| 55 | statement: "", |
| 56 | wantNil: true, |
| 57 | }, |
| 58 | { |
| 59 | description: "whitespace only", |
| 60 | statement: " \n\t ", |
| 61 | wantNil: true, |
| 62 | }, |
| 63 | { |
| 64 | description: "show commands", |
| 65 | statement: "show dbs\nshow collections", |
| 66 | wantCount: 2, |