summary refs log tree commit diff stats
path: root/tests/stdlib/nre/init.nim
blob: 26e66810410238f64186218fc3d789c5b3cba759 (plain) (blame)
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

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

  test "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))

  test "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))

  test "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")
<---- :(before "End Foo") //: .... //: ... //: ------------ //: <---------------------------- :(before "End Foo") //: .... //: ... //: // End Foo //: ============ //: //: Here's part of a layer in color: http://i.imgur.com/0eONnyX.png. Directives //: are shaded dark. //: //: Layers do more than just shuffle code around. In a well-organized codebase //: it should be possible to stop loading after any file/layer, build and run //: the program, and pass all tests for loaded features. (Relevant is //: http://youtube.com/watch?v=c8N72t7aScY, a scene from "2001: A Space //: Odyssey".) Get into the habit of running the included script called //: 'test_layers' before you commit any changes. //: //: This 'subsetting guarantee' ensures that this directory contains a //: cleaned-up narrative of the evolution of this codebase. Organizing //: autobiographically allows newcomers to rapidly orient themselves, reading //: the first few files to understand a simple gestalt of a program's core //: purpose and features, and later gradually working their way through other //: features as the need arises. //: //: Programmers shouldn't need to understand everything about a program to //: hack on it. But they shouldn't be prevented from a thorough understanding //: of each aspect either. The goal of layers is to reward curiosity. // Includes // End Includes // Types // End Types // Function prototypes are auto-generated in the 'build' script; define your // functions in any order. Just be sure to declare each function header all on // one line, ending with the '{'. Our auto-generation scripts are too minimal // and simple-minded to handle anything else. #include "function_list" // by convention, files ending with '_list' are auto-generated // Globals // // All statements in this section should always define a single variable on a // single line. The 'build' script will simple-mindedly auto-generate extern // declarations for them. Remember to define (not just declare) constants with // extern linkage in this section, since C++ global constants have internal // linkage by default. // // End Globals int main(int argc, char* argv[]) { atexit(reset); // we require a 32-bit little-endian system assert(sizeof(int) == 4); assert(sizeof(float) == 4); assert_little_endian(); // End One-time Setup // Commandline Parsing // End Commandline Parsing return 0; // End Main } // Unit Tests // End Unit Tests //: our first directive; insert the following headers at the start of the program :(before "End Includes") #include <assert.h> #include <stdlib.h> //: Without directives or with the :(code) directive, lines get added at the //: end. :(code) void reset() { // End Reset } void assert_little_endian() { const int x = 1; const char* y = reinterpret_cast<const char*>(&x); if (*y != 1) { cerr << "SubX requires a little-endian processor. Do you have Intel (or AMD or Atom) inside?\n"; exit(1); } } :(before "End Includes") #include<iostream> using std::cerr;