summary refs log tree commit diff stats
path: root/lib/system/chcks.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/system/chcks.nim')
-rw-r--r--lib/system/chcks.nim14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/system/chcks.nim b/lib/system/chcks.nim
index c018a7631..5c32a307a 100644
--- a/lib/system/chcks.nim
+++ b/lib/system/chcks.nim
@@ -13,13 +13,13 @@ proc raiseRangeError(val: BiggestInt) {.compilerproc, noreturn, noinline.} =
   when hostOS == "standalone":
     sysFatal(EOutOfRange, "value out of range")
   else:
-    sysFatal(EOutOfRange, "value out of range: ", $val)
+    sysFatal(RangeError, "value out of range: ", $val)
 
 proc raiseIndexError() {.compilerproc, noreturn, noinline.} =
-  sysFatal(EInvalidIndex, "index out of bounds")
+  sysFatal(IndexError, "index out of bounds")
 
 proc raiseFieldError(f: string) {.compilerproc, noreturn, noinline.} =
-  sysFatal(EInvalidField, f, " is not accessible")
+  sysFatal(FieldError, f, " is not accessible")
 
 proc chckIndx(i, a, b: int): int =
   if i >= a and i <= b:
@@ -46,11 +46,11 @@ proc chckRangeF(x, a, b: float): float =
     when hostOS == "standalone":
       sysFatal(EOutOfRange, "value out of range")
     else:
-      sysFatal(EOutOfRange, "value out of range: ", $x)
+      sysFatal(RangeError, "value out of range: ", $x)
 
 proc chckNil(p: pointer) =
   if p == nil:
-    sysFatal(EInvalidValue, "attempt to write to a nil address")
+    sysFatal(ValueError, "attempt to write to a nil address")
     #c_raise(SIGSEGV)
 
 proc chckObj(obj, subclass: PNimType) {.compilerproc.} =
@@ -59,13 +59,13 @@ proc chckObj(obj, subclass: PNimType) {.compilerproc.} =
   if x == subclass: return # optimized fast path
   while x != subclass:
     if x == nil:
-      sysFatal(EInvalidObjectConversion, "invalid object conversion")
+      sysFatal(ObjectConversionError, "invalid object conversion")
       break
     x = x.base
 
 proc chckObjAsgn(a, b: PNimType) {.compilerproc, inline.} =
   if a != b:
-    sysFatal(EInvalidObjectAssignment, "invalid object assignment")
+    sysFatal(ObjectAssignmentError, "invalid object assignment")
 
 type ObjCheckCache = array[0..1, PNimType]
 
2015-01-10 16:20:25 -0500 committer Flaviu Tamas <tamasflaviu@gmail.com> 2015-01-10 16:20:25 -0500 Implement captures' href='/ahoang/Nim/commit/test/captures.nim?h=devel&id=721ea11628a3717b07c1867096e817f06068a24e'>721ea1162 ^
f141737b9 ^
c0a47f7e2 ^
721ea1162 ^

f141737b9 ^
721ea1162 ^


f141737b9 ^
c0a47f7e2 ^
721ea1162 ^
c0a47f7e2 ^


721ea1162 ^

f141737b9 ^
c0a47f7e2 ^




48c29ac90 ^

f141737b9 ^
48c29ac90 ^
fb51221aa ^
0f4b142c7 ^

f141737b9 ^
c0a47f7e2 ^

0f4b142c7 ^
f141737b9 ^
d62b41fa1 ^
0f4b142c7 ^

f141737b9 ^
c0a47f7e2 ^
9576bc087 ^
c0a47f7e2 ^
0f4b142c7 ^
f141737b9 ^
c0a47f7e2 ^
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
60
61
62
63
64
                                   



                                      
                                                                           


                                                           
                           
                                                 
                                                      

                                                    
 
                                               

                                                      
 
                            
                                                     

                        
                                                         


                                       
                                                       
                                     
                                       


                                      

                              
                                                       




                                           

                       
                                           
                                
                                                                

                             
                                                       

                                                                
 
                                                          
                                                                           

                          
                                                       
                                                             
                                                                     
                                                                   
 
                                                          
                                                            
 
import unittest, optional_nonstrict
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 .. 0)
    check("1 23".find(ex1).captureBounds[0] == 0 .. 0)
    check("1 23".find(ex1, 1).matchBounds == 2 .. 2)
    check("1 23".find(ex1, 3).matchBounds == 3 .. 3)

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

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

  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("foo" in ex2.captureBounds)
    check(ex2.captures["foo"] == "foo")
    check(not ("bar" in ex2.captures))
    expect KeyError:
        discard ex2.captures["bar"]

  test "named capture bounds":
    let ex1 = "foo".find(re("(?<foo>foo)(?<bar>bar)?"))
    check("foo" in ex1.captureBounds)
    check(ex1.captureBounds["foo"] == 0..2)
    check(not ("bar" in ex1.captures))
    expect KeyError:
        discard ex1.captures["bar"]

  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"}.toTable())
    check(ex1.captureBounds.toTable == {"foo" : 0..2}.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 == @[some("foo"), none(string)])
    check(ex1.captureBounds.toSeq == @[some(0..2), none(Slice[int])])
    check(ex1.captures.toSeq(some("")) == @[some("foo"), some("")])

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