Check-in [b37c997693]
Overview
SHA1:b37c99769364b66e606daf864bf101f0470c88f1
Date: 2015-03-19 20:40:13
User: spaskalev
Comment:Added a test for parse.Defer
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2015-03-19
20:51
[61937abf4c] Added parse.Digit and a test (user: spaskalev, tags: trunk)
20:40
[b37c997693] Added a test for parse.Defer (user: spaskalev, tags: trunk)
20:36
[893c36d683] Added a string matching parser. (user: spaskalev, tags: trunk)
Changes

Modified src/0dev.org/parse/parse_test.go from [b6485539c4] to [eebf67dde7].

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
..
51
52
53
54
55
56
57











58
59
60
61
62
63
64
65
66
67
	"testing"
)

func TestAccept(t *testing.T) {
	// Accept(0) will always match :)
	p0 := Accept(0)
	if n, r := p0(""); !n.Matched || n.Content != "" || n.Nodes != nil || r != "" {
		t.Error("Invalid result for Accept's negative test", n)
	}
	// Test with a non-zero amount of bytes
	p := Accept(1)
	if n, r := p(""); n.Matched || n.Content != "" || n.Nodes != nil || r != "" {
		t.Error("Invalid result for Accept's negative test", n)
	}
	if n, r := p("a"); !n.Matched || n.Content != "a" || n.Nodes != nil || r != "" {
		t.Error("Invalid result for Accept's positive test", n)
	}
}

func TestK(t *testing.T) {
	p := Accept(1)
	k := K(p)
	if n, r := k("aaa"); !n.Matched || n.Content != "aaa" || n.Nodes == nil || r != "" {
................................................................................
	if n, r := a(""); !n.Matched || n.Content != "" || n.Nodes != nil || r != "" {
		t.Error("Invalid result for Any match test", n)
	}
	if n, r := a("aa"); !n.Matched || n.Content != "a" || n.Nodes != nil || r != "a" {
		t.Error("Invalid result for Any match test", n)
	}
}












func TestString(t *testing.T) {
	s := String("aa")
	if n, r := s("aa"); !n.Matched || n.Content != "aa" || n.Nodes != nil || r != "" {
		t.Error("Invalid result for String match test", n)
	}
	if n, r := s("ab"); n.Matched || n.Content != "" || n.Nodes == nil || r != "ab" {
		t.Error("Invalid result for String no-match test", n, r, len(r))
	}
}







|




|


|







 







>
>
>
>
>
>
>
>
>
>
>










4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
..
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
	"testing"
)

func TestAccept(t *testing.T) {
	// Accept(0) will always match :)
	p0 := Accept(0)
	if n, r := p0(""); !n.Matched || n.Content != "" || n.Nodes != nil || r != "" {
		t.Error("Invalid result for Accept empty match test", n)
	}
	// Test with a non-zero amount of bytes
	p := Accept(1)
	if n, r := p(""); n.Matched || n.Content != "" || n.Nodes != nil || r != "" {
		t.Error("Invalid result for Accept no-match test", n)
	}
	if n, r := p("a"); !n.Matched || n.Content != "a" || n.Nodes != nil || r != "" {
		t.Error("Invalid result for Accept match test", n)
	}
}

func TestK(t *testing.T) {
	p := Accept(1)
	k := K(p)
	if n, r := k("aaa"); !n.Matched || n.Content != "aaa" || n.Nodes == nil || r != "" {
................................................................................
	if n, r := a(""); !n.Matched || n.Content != "" || n.Nodes != nil || r != "" {
		t.Error("Invalid result for Any match test", n)
	}
	if n, r := a("aa"); !n.Matched || n.Content != "a" || n.Nodes != nil || r != "a" {
		t.Error("Invalid result for Any match test", n)
	}
}

func TestDefer(t *testing.T) {
	d, dp := Defer()
	*dp = Accept(1)
	if n, r := d(""); n.Matched || n.Content != "" || n.Nodes != nil || r != "" {
		t.Error("Invalid result for Defer no-match test", n)
	}
	if n, r := d("a"); !n.Matched || n.Content != "a" || n.Nodes != nil || r != "" {
		t.Error("Invalid result for Defer match test", n)
	}
}

func TestString(t *testing.T) {
	s := String("aa")
	if n, r := s("aa"); !n.Matched || n.Content != "aa" || n.Nodes != nil || r != "" {
		t.Error("Invalid result for String match test", n)
	}
	if n, r := s("ab"); n.Matched || n.Content != "" || n.Nodes == nil || r != "ab" {
		t.Error("Invalid result for String no-match test", n, r, len(r))
	}
}