File: ci_tests.pike

package info (click to toggle)
pike8.0 8.0.702-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 79,608 kB
  • sloc: ansic: 266,508; xml: 186,324; makefile: 3,537; sh: 1,731; cpp: 1,328; lisp: 655; awk: 441; asm: 242; objc: 240; pascal: 157; perl: 34; sed: 34
file content (129 lines) | stat: -rw-r--r-- 3,038 bytes parent folder | download | duplicates (2)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129


void main(int num, array args) {

  if(num<2 || args[1]=="--help")
    exit(0, #"Creates upper/lower case tests for testsuite.in.
Takes case_info.h as argument.
");

  string s = Stdio.read_file(args[1]);
  array ci = ({});
  int off, ch;
  string type, sign;
  while( sscanf(s, "%*s{ 0x%x, %s, %sx%x, },%s", off, type, sign, ch, s)==6) {
    if(sign=="-0")
      ch = -ch;
    ci += ({ ({ off, type, ch }) });
  }

  array a = ({});
  array b = ({});
  array B = ({});
  foreach(ci; int pos; array r) {
    int char = r[0];
    int delta = r[2];
    a += ({ char });
    switch(r[1]) {
    case "CIM_NONE":
      b += ({ char });
      B += ({ char });
      break;

    case "CIM_LONGLOWERDELTA":
      if( delta < 0 )
        delta -= 0x8000;
      else
        delta += 0x7fff;
      // Fallthrough
    case "CIM_LOWERDELTA":
      b += ({ char });
      B += ({ char-delta });
      break;

    case "CIM_LONGUPPERDELTA":
      if( delta < 0 )
        delta -= 0x8000;
      else
        delta += 0x7fff;
      // Fallthrough
    case "CIM_UPPERDELTA":
      b += ({ char + delta });
      B += ({ char });
      break;

    case "CIM_CASEBIT":
      b += ({ char | delta });
      B += ({ char & ~delta });
      break;
    case "CIM_CASEBITOFF":
      b += ({ ((char-delta) | delta) + delta });
      B += ({ ((char-delta) & ~delta) + delta });
      break;
    default:
      exit(1, "Error in case_info.h: Unknown type %s\n", r[1]);
    }

    if( B[-1]<0 )
      exit(1, "Error in case_info.h. Negative char { %04x, %s %04x }\n",
           @r);
    if( b[-1]<0 )
      exit(1, "Error in case_info.h. Negative char { %04x, %s %04x }\n",
           @r);
  }

  // Insert hard coded rules
  a = a[0..0] + ({ 0x41, 0x5b, 0x61, 0x7b }) + a[1..];
  b = b[0..0] + ({ 0x61, 0x5b, 0x61, 0x7b }) + b[1..];
  B = B[0..0] + ({ 0x41, 0x5b, 0x41, 0x7b }) + B[1..];

  make_test("lower", a, b);
  write("\n\n\n\n");
  make_test("upper", a, B);
}

void make_test(string f, array a, array b) {
  write(#"test_equal(%s_case((string) ({
// These characters correspond to the cases in case_info.h
// Please update this and the corresponding %s_case table
// when UnicodeData.txt is changed.
// Part 1: 0x0000 - 0x0FFF
", f, (["upper":"lower","lower":"upper"])[f] );

  int pos;
  while(a[pos]<0x0FFF) {
    write("0x%04x, ", a[pos++]);
    if(!(pos%8)) write("\n");
  }

  write("})), (string) ({\n");

  for(int i; i<pos; i++) {
    write("0x%04x, ", b[i]);
    if(!((i+1)%8)) write("\n");
  }

  write("}))\n");

  write(#"test_equal(%s_case((string) ({
// These characters correspond to the cases in case_info.h
// Please update this and the corresponding %s_case table
// when UnicodeData.txt is changed.
// Part 2: 0x1000 -
", f, (["upper":"lower","lower":"upper"])[f] );

  for(int i=pos,x=1; i<sizeof(a); i++,x++) {
    write("0x%04x, ", a[i]);
    if(!(x%8)) write("\n");
  }

  write("})), (string) ({\n");

  for(int i=pos,x=1; i<sizeof(b); i++,x++) {
    write("0x%04x, ", b[i]);
    if(!(x%8)) write("\n");
  }

  write("}))\n");

}