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      4   	"testing"
     5      5   )
     6      6   
     7      7   func TestAccept(t *testing.T) {
     8      8   	// Accept(0) will always match :)
     9      9   	p0 := Accept(0)
    10     10   	if n, r := p0(""); !n.Matched || n.Content != "" || n.Nodes != nil || r != "" {
    11         -		t.Error("Invalid result for Accept's negative test", n)
           11  +		t.Error("Invalid result for Accept empty match test", n)
    12     12   	}
    13     13   	// Test with a non-zero amount of bytes
    14     14   	p := Accept(1)
    15     15   	if n, r := p(""); n.Matched || n.Content != "" || n.Nodes != nil || r != "" {
    16         -		t.Error("Invalid result for Accept's negative test", n)
           16  +		t.Error("Invalid result for Accept no-match test", n)
    17     17   	}
    18     18   	if n, r := p("a"); !n.Matched || n.Content != "a" || n.Nodes != nil || r != "" {
    19         -		t.Error("Invalid result for Accept's positive test", n)
           19  +		t.Error("Invalid result for Accept match test", n)
    20     20   	}
    21     21   }
    22     22   
    23     23   func TestK(t *testing.T) {
    24     24   	p := Accept(1)
    25     25   	k := K(p)
    26     26   	if n, r := k("aaa"); !n.Matched || n.Content != "aaa" || n.Nodes == nil || r != "" {
................................................................................
    51     51   	if n, r := a(""); !n.Matched || n.Content != "" || n.Nodes != nil || r != "" {
    52     52   		t.Error("Invalid result for Any match test", n)
    53     53   	}
    54     54   	if n, r := a("aa"); !n.Matched || n.Content != "a" || n.Nodes != nil || r != "a" {
    55     55   		t.Error("Invalid result for Any match test", n)
    56     56   	}
    57     57   }
           58  +
           59  +func TestDefer(t *testing.T) {
           60  +	d, dp := Defer()
           61  +	*dp = Accept(1)
           62  +	if n, r := d(""); n.Matched || n.Content != "" || n.Nodes != nil || r != "" {
           63  +		t.Error("Invalid result for Defer no-match test", n)
           64  +	}
           65  +	if n, r := d("a"); !n.Matched || n.Content != "a" || n.Nodes != nil || r != "" {
           66  +		t.Error("Invalid result for Defer match test", n)
           67  +	}
           68  +}
    58     69   
    59     70   func TestString(t *testing.T) {
    60     71   	s := String("aa")
    61     72   	if n, r := s("aa"); !n.Matched || n.Content != "aa" || n.Nodes != nil || r != "" {
    62     73   		t.Error("Invalid result for String match test", n)
    63     74   	}
    64     75   	if n, r := s("ab"); n.Matched || n.Content != "" || n.Nodes == nil || r != "ab" {
    65     76   		t.Error("Invalid result for String no-match test", n, r, len(r))
    66     77   	}
    67     78   }