mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-02-08 00:21:23 +01:00
words -> str. test roundtrip
This commit is contained in:
parent
06724528cc
commit
b9fd4df60f
@ -18,6 +18,11 @@ func testParse(t *testing.T, s string) {
|
|||||||
fmt.Printf("%s\n", s)
|
fmt.Printf("%s\n", s)
|
||||||
dumpWords(words, " ")
|
dumpWords(words, " ")
|
||||||
fmt.Printf("\n")
|
fmt.Printf("\n")
|
||||||
|
|
||||||
|
outStr := wordsToStr(words)
|
||||||
|
if outStr != s {
|
||||||
|
t.Errorf("tokenization output does not match input: %q => %q", s, outStr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test1(t *testing.T) {
|
func Test1(t *testing.T) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package shparse
|
package shparse
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -108,3 +109,14 @@ func Tokenize(cmd string) []*wordType {
|
|||||||
state.finish(c)
|
state.finish(c)
|
||||||
return state.Rtn
|
return state.Rtn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func wordsToStr(words []*wordType) string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
for _, word := range words {
|
||||||
|
if len(word.Prefix) > 0 {
|
||||||
|
buf.WriteString(string(word.Prefix))
|
||||||
|
}
|
||||||
|
buf.WriteString(string(word.Raw))
|
||||||
|
}
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user