OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [regexp/] [syntax/] [prog_test.go] - Blame information for rev 774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2011 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
package syntax_test
6
 
7
import (
8
        . "regexp/syntax"
9
        "testing"
10
)
11
 
12
var compileTests = []struct {
13
        Regexp string
14
        Prog   string
15
}{
16
        {"a", `  0      fail
17
  1*    rune1 "a" -> 2
18
  2     match
19
`},
20
        {"[A-M][n-z]", `  0     fail
21
  1*    rune "AM" -> 2
22
  2     rune "nz" -> 3
23
  3     match
24
`},
25
        {"", `  0       fail
26
  1*    nop -> 2
27
  2     match
28
`},
29
        {"a?", `  0     fail
30
  1     rune1 "a" -> 3
31
  2*    alt -> 1, 3
32
  3     match
33
`},
34
        {"a??", `  0    fail
35
  1     rune1 "a" -> 3
36
  2*    alt -> 3, 1
37
  3     match
38
`},
39
        {"a+", `  0     fail
40
  1*    rune1 "a" -> 2
41
  2     alt -> 1, 3
42
  3     match
43
`},
44
        {"a+?", `  0    fail
45
  1*    rune1 "a" -> 2
46
  2     alt -> 3, 1
47
  3     match
48
`},
49
        {"a*", `  0     fail
50
  1     rune1 "a" -> 2
51
  2*    alt -> 1, 3
52
  3     match
53
`},
54
        {"a*?", `  0    fail
55
  1     rune1 "a" -> 2
56
  2*    alt -> 3, 1
57
  3     match
58
`},
59
        {"a+b+", `  0   fail
60
  1*    rune1 "a" -> 2
61
  2     alt -> 1, 3
62
  3     rune1 "b" -> 4
63
  4     alt -> 3, 5
64
  5     match
65
`},
66
        {"(a+)(b+)", `  0       fail
67
  1*    cap 2 -> 2
68
  2     rune1 "a" -> 3
69
  3     alt -> 2, 4
70
  4     cap 3 -> 5
71
  5     cap 4 -> 6
72
  6     rune1 "b" -> 7
73
  7     alt -> 6, 8
74
  8     cap 5 -> 9
75
  9     match
76
`},
77
        {"a+|b+", `  0  fail
78
  1     rune1 "a" -> 2
79
  2     alt -> 1, 6
80
  3     rune1 "b" -> 4
81
  4     alt -> 3, 6
82
  5*    alt -> 1, 3
83
  6     match
84
`},
85
        {"A[Aa]", `  0  fail
86
  1*    rune1 "A" -> 2
87
  2     rune "A"/i -> 3
88
  3     match
89
`},
90
        {"(?:(?:^).)", `  0     fail
91
  1*    empty 4 -> 2
92
  2     anynotnl -> 3
93
  3     match
94
`},
95
}
96
 
97
func TestCompile(t *testing.T) {
98
        for _, tt := range compileTests {
99
                re, _ := Parse(tt.Regexp, Perl)
100
                p, _ := Compile(re)
101
                s := p.String()
102
                if s != tt.Prog {
103
                        t.Errorf("compiled %#q:\n--- have\n%s---\n--- want\n%s---", tt.Regexp, s, tt.Prog)
104
                }
105
        }
106
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.