Adding the challenge 0302

This commit is contained in:
2026-07-30 21:19:53 +02:00
parent 89975de979
commit 185ba1878e
15 changed files with 868 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
package db0302
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseName(t *testing.T) {
p := NewParser(" a b0 _0_ 123 ")
name, ok := p.tryName()
assert.True(t, ok && name == "a")
name, ok = p.tryName()
assert.True(t, ok && name == "b0")
name, ok = p.tryName()
assert.True(t, ok && name == "_0_")
_, ok = p.tryName()
assert.False(t, ok)
}
func TestParseKeyword(t *testing.T) {
p := NewParser(" select HELLO ")
assert.False(t, p.tryKeyword("sel"))
assert.True(t, p.tryKeyword("SELECT"))
assert.True(t, p.tryKeyword("hello") && p.isEnd())
}
func testParseValue(t *testing.T, s string, ref Cell) {
p := NewParser(s)
out := Cell{}
err := p.parseValue(&out)
assert.Nil(t, err)
assert.True(t, p.isEnd())
assert.Equal(t, ref, out)
}
func TestParseValue(t *testing.T) {
testParseValue(t, " -123 ", Cell{Type: TypeI64, I64: -123})
testParseValue(t, ` 'abc\'\"d' `, Cell{Type: TypeStr, Str: []byte("abc'\"d")})
testParseValue(t, ` "abc\'\"d" `, Cell{Type: TypeStr, Str: []byte("abc'\"d")})
}
// QzBQWVJJOUhU https://trialofcode.org/