diff options
| author | Shulhan <ms@kilabit.info> | 2023-10-07 16:03:09 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-10-07 16:03:09 +0700 |
| commit | 27a0a85d657d139b73e61d48a38628a6e3b682ed (patch) | |
| tree | bed2a8bf4f8adde6f4dd26d0b148ad388ae5b4eb /statement_test.go | |
| parent | 1951152c8dedda62f6a7b00f9b1bedfc427482c6 (diff) | |
| download | awwan-27a0a85d657d139b73e61d48a38628a6e3b682ed.tar.xz | |
all: simplify parsing statement for magic command "#put"
This changes minimize code duplication when parsing magic command
between "#put:" and "#put!" using single function parseStatementGetPut.
In the returned Statement, we changes where to store the source argument
into args[0] instead of in cmd for better readability and minimize
confusion in Copy/SudoCopy.
Diffstat (limited to 'statement_test.go')
| -rw-r--r-- | statement_test.go | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/statement_test.go b/statement_test.go index 51e8481..ea4df45 100644 --- a/statement_test.go +++ b/statement_test.go @@ -56,19 +56,35 @@ func TestParseStatement(t *testing.T) { raw: []byte(` a\ b c`), }, }, { - raw: []byte(`#put: a b c\ `), + raw: []byte(`#put: `), + expError: `ParseStatement: "#put:": missing arguments`, + }, { + raw: []byte(`#put: src `), + expError: `ParseStatement: "#put:": missing destination file`, + }, { + raw: []byte(`#put: src dst dst2 `), + expError: `ParseStatement: "#put:": too many arguments`, + }, { + raw: []byte(`#put: a bc\ `), exp: &Statement{ kind: statementKindPut, - cmd: "a", - args: []string{"b", `c`}, - raw: []byte(` a b c\`), + args: []string{`a`, `bc`}, + raw: []byte(` a bc\`), }, }, { + raw: []byte(`#put! `), + expError: `ParseStatement: "#put!": missing arguments`, + }, { + raw: []byte(`#put! src `), + expError: `ParseStatement: "#put!": missing destination file`, + }, { + raw: []byte(`#put! src dst dst2 `), + expError: `ParseStatement: "#put!": too many arguments`, + }, { raw: []byte(`#put! a bc `), exp: &Statement{ kind: statementKindSudoPut, - cmd: `a`, - args: []string{"bc"}, + args: []string{`a`, `bc`}, raw: []byte(` a bc`), }, }, { |
