diff options
| author | Shulhan <ms@kilabit.info> | 2021-08-11 16:56:50 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2021-08-22 17:23:15 +0700 |
| commit | db5c26d8f61aa0fedc5854b649f7914054397a81 (patch) | |
| tree | 9fb0ac785f16fb0ea990d98dfdf66b6b8248e4dd /statement_test.go | |
| parent | 45485c7232e95acbe7b6ffbe31c9f40ca17ea774 (diff) | |
| download | awwan-db5c26d8f61aa0fedc5854b649f7914054397a81.tar.xz | |
all: rewrite the Session and Script using Statement
The idea for rewrite is to separate between local and remote script, so
we can apply environment variables to local script. We also parse and
validate each statements before being executed to simplify the code.
Diffstat (limited to 'statement_test.go')
| -rw-r--r-- | statement_test.go | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/statement_test.go b/statement_test.go new file mode 100644 index 0000000..559cf50 --- /dev/null +++ b/statement_test.go @@ -0,0 +1,73 @@ +// Copyright 2021, Shulhan <ms@kilabit.info>. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package awwan + +import ( + "testing" + + "github.com/shuLhan/share/lib/test" +) + +func TestParseStatement(t *testing.T) { + cases := []struct { + raw []byte + exp *Statement + }{{ + raw: []byte(`#get: a\ b c`), + exp: &Statement{ + kind: statementKindGet, + cmd: `a b`, + args: []string{"c"}, + raw: []byte(` a\ b c`), + }, + }, { + raw: []byte(`#put: a b c\ `), + exp: &Statement{ + kind: statementKindPut, + cmd: "a", + args: []string{"b", `c`}, + raw: []byte(` a b c\`), + }, + }, { + raw: []byte(`#get! a\ b c`), + exp: &Statement{ + kind: statementKindSudoGet, + cmd: `a b`, + args: []string{ + "c", + }, + raw: []byte(` a\ b c`), + }, + }, { + raw: []byte(`#put! a bc `), + exp: &Statement{ + kind: statementKindSudoPut, + cmd: `a`, + args: []string{"bc"}, + raw: []byte(` a bc`), + }, + }, { + raw: []byte(`#require:\ a\ `), + exp: &Statement{ + kind: statementKindRequire, + cmd: ` a`, + raw: []byte(`\ a\`), + }, + }, { + raw: []byte(`#requ: a `), + exp: &Statement{ + kind: statementKindComment, + raw: []byte(`#requ: a`), + }, + }} + + for _, c := range cases { + got, err := ParseStatement(c.raw) + if err != nil { + t.Fatal(err) + } + test.Assert(t, string(c.raw), c.exp, got) + } +} |
