File: init.nim

package info (click to toggle)
nim 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,911,644 kB
  • sloc: sh: 24,603; ansic: 1,761; python: 1,492; makefile: 1,013; sql: 298; asm: 141; xml: 13
file content (36 lines) | stat: -rw-r--r-- 1,178 bytes parent folder | download | duplicates (3)
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
import unittest
include nre

block: # Test NRE initialization
  block: # correct initialization
    check(re("[0-9]+") != nil)
    check(re("(?i)[0-9]+") != nil)

  block: # options
    check(extractOptions("(*NEVER_UTF)") ==
          ("", pcre.NEVER_UTF, true))
    check(extractOptions("(*UTF8)(*ANCHORED)(*UCP)z") ==
          ("(*UTF8)(*UCP)z", pcre.ANCHORED, true))
    check(extractOptions("(*ANCHORED)(*UTF8)(*JAVASCRIPT_COMPAT)z") ==
          ("(*UTF8)z", pcre.ANCHORED or pcre.JAVASCRIPT_COMPAT, true))

    check(extractOptions("(*NO_STUDY)(") == ("(", 0, false))

    check(extractOptions("(*LIMIT_MATCH=6)(*ANCHORED)z") ==
          ("(*LIMIT_MATCH=6)z", pcre.ANCHORED, true))

  block: # incorrect options
    for s in ["CR", "(CR", "(*CR", "(*abc)", "(*abc)CR",
              "(?i)",
              "(*LIMIT_MATCH=5", "(*NO_AUTO_POSSESS=5)"]:
      let ss = s & "(*NEVER_UTF)"
      check(extractOptions(ss) == (ss, 0, true))

  block: # invalid regex
    expect(SyntaxError): discard re("[0-9")
    try:
      discard re("[0-9")
    except SyntaxError:
      let ex = SyntaxError(getCurrentException())
      check(ex.pos == 4)
      check(ex.pattern == "[0-9")