summary refs log tree commit diff stats
path: root/doc/regexprs.txt
Commit message (Expand)AuthorAgeFilesLines
* Nimrod renamed to NimAraq2014-08-281-2/+2
* Removes executable bit for text files.Grzegorz Adam Hankiewicz2013-03-161-0/+0
* fixed pango/pangoutils new wrappersAndreas Rumpf2010-02-261-0/+0
* continued work on html/xmlparserrumpf_a@web.de2010-02-141-0/+0
* added tools and web dirsAndreas Rumpf2009-09-151-0/+0
* too many changes to listAndreas Rumpf2008-08-231-22/+0
* first releaseRumpf2008-06-231-0/+0
* Initial importAndreas Rumpf2008-06-221-0/+296
aviu Tamas <tamasflaviu@gmail.com> 2015-01-18 13:04:56 -0500 committer Flaviu Tamas <tamasflaviu@gmail.com> 2015-01-18 13:04:56 -0500 Remove initRegex' href='/ahoang/Nim/commit/test/captures.nim?h=devel&id=f141737b9f677fadfd24a7e84bed6d3f9102c780'>f141737b9 ^
1a5401ebc ^

721ea1162 ^
f141737b9 ^
1a5401ebc ^
721ea1162 ^

f141737b9 ^
721ea1162 ^


f141737b9 ^
721ea1162 ^



f141737b9 ^
721ea1162 ^

48c29ac90 ^

f141737b9 ^
48c29ac90 ^
fb51221aa ^
0f4b142c7 ^

f141737b9 ^
d62b41fa1 ^


0f4b142c7 ^
f141737b9 ^
d62b41fa1 ^
0f4b142c7 ^

f141737b9 ^
d649cec03 ^


0f4b142c7 ^
f141737b9 ^
d649cec03 ^
0f4b142c7 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59




                                      
                                                                            


                                                           
                           



                                                          
 
                                               

                                                          
 
                            
                                                         

                        
                                                         


                                       
                                                       



                                       
                                                       

                                                         

                       
                                           
                                
                                                                

                             
                                                       


                                                                                                  
 
                                                          
                                                                           

                          
                                                       


                                                                       
 
                                                          
                                                
 
import unittest
include nre

suite "captures":
  test "map capture names to numbers":
    check(getNameToNumberTable(re("(?<v1>1(?<v2>2(?<v3>3))(?'v4'4))()")) == 
      { "v1" : 0, "v2" : 1, "v3" : 2, "v4" : 3 }.toTable())

  test "capture bounds are correct":
    let ex1 = re("([0-9])")
    check("1 23".find(ex1).matchBounds == 0 .. 1)
    check("1 23".find(ex1).captureBounds[0].get == 0 .. 1)
    check("1 23".find(ex1, 1).matchBounds == 2 .. 3)
    check("1 23".find(ex1, 3).matchBounds == 3 .. 4)

    let ex2 = re("()()()()()()()()()()([0-9])")
    check("824".find(ex2).captureBounds[0].get == 0 .. 0)
    check("824".find(ex2).captureBounds[10].get == 0 .. 1)

    let ex3 = re("([0-9]+)")
    check("824".find(ex3).captureBounds[0].get == 0 .. 3)

  test "named captures":
    let ex1 = "foobar".find(re("(?<foo>foo)(?<bar>bar)"))
    check(ex1.captures["foo"] == "foo")
    check(ex1.captures["bar"] == "bar")

    let ex2 = "foo".find(re("(?<foo>foo)(?<bar>bar)?"))
    check(ex2.captures["foo"] == "foo")
    check(ex2.captures["bar"] == nil)

  test "named capture bounds":
    let ex1 = "foo".find(re("(?<foo>foo)(?<bar>bar)?"))
    check(ex1.captureBounds["foo"] == Some(0..3))
    check(ex1.captureBounds["bar"] == None[Slice[int]]())

  test "capture count":
    let ex1 = re("(?<foo>foo)(?<bar>bar)?")
    check(ex1.captureCount == 2)
    check(ex1.captureNameId == {"foo" : 0, "bar" : 1}.toTable())

  test "named capture table":
    let ex1 = "foo".find(re("(?<foo>foo)(?<bar>bar)?"))
    check(ex1.captures.toTable == {"foo" : "foo", "bar" : nil}.toTable())
    check(ex1.captureBounds.toTable == {"foo" : Some(0..3), "bar" : None[Slice[int]]()}.toTable())
    check(ex1.captures.toTable("") == {"foo" : "foo", "bar" : ""}.toTable())

    let ex2 = "foobar".find(re("(?<foo>foo)(?<bar>bar)?"))
    check(ex2.captures.toTable == {"foo" : "foo", "bar" : "bar"}.toTable())

  test "capture sequence":
    let ex1 = "foo".find(re("(?<foo>foo)(?<bar>bar)?"))
    check(ex1.captures.toSeq == @["foo", nil])
    check(ex1.captureBounds.toSeq == @[Some(0..3), None[Slice[int]]()])
    check(ex1.captures.toSeq("") == @["foo", ""])

    let ex2 = "foobar".find(re("(?<foo>foo)(?<bar>bar)?"))
    check(ex2.captures.toSeq == @["foo", "bar"])