Skip to content

Commit 83dc3b2

Browse files
authored
wdte: Fix PatternAssigner.String() (#197)
* wdte: Update some dependencies. * repl: Add a 'test'. Kind of. Not really. * wdte: Fix `PatternAssigner.String()`.
1 parent a79cfa9 commit 83dc3b2

File tree

5 files changed

+60
-15
lines changed

5 files changed

+60
-15
lines changed

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module github.com/DeedleFake/wdte
22

33
require (
4-
github.com/mattn/go-runewidth v0.0.4 // indirect
5-
github.com/peterh/liner v1.1.0
6-
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4
7-
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb // indirect
4+
github.com/mattn/go-runewidth v0.0.8 // indirect
5+
github.com/peterh/liner v1.2.0
6+
golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6
7+
golang.org/x/sys v0.0.0-20200217220822-9197077df867 // indirect
88
)
99

1010
go 1.13

go.sum

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4=
22
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
3-
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
4-
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
5-
github.com/peterh/liner v1.1.0 h1:f+aAedNJA6uk7+6rXsYBnhdo4Xux7ESLe+kcuVUF5os=
6-
github.com/peterh/liner v1.1.0/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0=
3+
github.com/mattn/go-runewidth v0.0.8 h1:3tS41NlGYSmhhe/8fhGRzc+z3AYCw1Fe1WAyLuujKs0=
4+
github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
5+
github.com/peterh/liner v1.2.0 h1:w/UPXyl5GfahFxcTOz2j9wCIHNI+pUPr2laqpojKNCg=
6+
github.com/peterh/liner v1.2.0/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0=
77
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
8-
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 h1:ydJNl0ENAG67pFbB+9tfhiL2pYqLhfoaZFw/cjLhY4A=
9-
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
8+
golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6 h1:Sy5bstxEqwwbYs6n0/pBuxKENqOeZUgD45Gp3Q3pqLg=
9+
golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
10+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
1011
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
1112
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
1213
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
13-
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k=
14-
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
15-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
14+
golang.org/x/sys v0.0.0-20200217220822-9197077df867 h1:JoRuNIf+rpHl+VhScRQQvzbHed86tKkqwPMV34T8myw=
15+
golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
16+
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
17+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

repl/repl_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package repl_test
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"strings"
7+
"testing"
8+
9+
"github.com/DeedleFake/wdte/repl"
10+
"github.com/DeedleFake/wdte/std"
11+
)
12+
13+
func TestREPL(t *testing.T) {
14+
src := bufio.NewReader(strings.NewReader(`let test [a b] => + a b;`))
15+
r := repl.New(func() ([]byte, error) {
16+
return src.ReadBytes('\n')
17+
}, std.Import, nil, nil)
18+
19+
ret, err := r.Next()
20+
if err != nil {
21+
t.Error(err)
22+
}
23+
24+
fmt.Printf("%#v\n", ret)
25+
}

wdte.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"io"
88
"sort"
99
"strings"
10-
"unsafe"
1110

1211
"github.com/DeedleFake/wdte/ast"
1312
"github.com/DeedleFake/wdte/scanner"
@@ -920,7 +919,21 @@ func (a PatternAssigner) IDs() []ID {
920919
}
921920

922921
func (a PatternAssigner) String() string {
923-
return "[" + strings.Join(*(*[]string)(unsafe.Pointer(&a)), " ") + "]"
922+
var buf strings.Builder
923+
924+
buf.WriteByte('[')
925+
926+
sep := ""
927+
for _, a := range a {
928+
buf.WriteString(sep)
929+
buf.WriteString(fmt.Sprint(a))
930+
931+
sep = " "
932+
}
933+
934+
buf.WriteByte(']')
935+
936+
return buf.String()
924937
}
925938

926939
// A LetAssigner assigns a pre-defined expression using an Assigner.

wdte_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,11 @@ func TestStrings(t *testing.T) {
839839
script: `let str => import 'strings'; str.format '{}' (@ s n => + n 2);`,
840840
ret: wdte.String(`(@ s n => ...)`),
841841
},
842+
{
843+
name: "Format/Lambda/Pattern",
844+
script: `let str => import 'strings'; str.format '{}' (@ s [a b] => + a b);`,
845+
ret: wdte.String(`(@ s [a b] => ...)`),
846+
},
842847
{
843848
name: "Format/Partial",
844849
script: `let str => import 'strings'; let t => str.format '{} + {}: {}' 3 2; + 3 2 -> t;`,

0 commit comments

Comments
 (0)