This file is indexed.

/usr/lib/Wt/test/private/CExpressionParserTest.C is in witty-examples 3.3.0-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 * Copyright (C) 2009 Emweb bvba, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */

#include <Wt/WMessageResources>
#include <boost/test/unit_test.hpp>

namespace {
  int eval(std::string expression, ::uint64_t n) 
  {
    return Wt::WMessageResources::evalPluralCase(expression, n);
  }
}

BOOST_AUTO_TEST_CASE( cexpression_basic_expression_test )
{
  {
    std::string e = "1 + 2";
    BOOST_REQUIRE(eval(e, -1) == 3);
  }

  {
    std::string e = "1 + n";
    BOOST_REQUIRE(eval(e, 2) == 3);
  }

  {
    std::string e = "3 - n";
    BOOST_REQUIRE(eval(e, 2) == 1);
  }

  {
    std::string e = "3 * n";
    BOOST_REQUIRE(eval(e, 2) == 6);
  }

  {
    std::string e = "4 / n";
    BOOST_REQUIRE(eval(e, 2) == 2);
  }

  {
    std::string e = "5 % n";
    BOOST_REQUIRE(eval(e, 2) == 1);
  }

  {
    std::string e = "(5 + n) * (n + 2) + (n * n)";
    BOOST_REQUIRE(eval(e, 3) == 49);
  }

  {
    std::string e = "n == 4";
    BOOST_REQUIRE(eval(e, 4) == 1);
  }

  {
    std::string e = "n == 3";
    std::string e2 = "n != 3";
    BOOST_REQUIRE(eval(e, 4) == 0);
    BOOST_REQUIRE(eval(e2, 4) == 1);
    BOOST_REQUIRE(eval(e + " && " + e2, 4) == 0);
    BOOST_REQUIRE(eval(e + " || " + e2, 4) == 1);

    std::string te = e + " ? n + 3 : n * n";
    BOOST_REQUIRE(eval(te, 3) == 6);
    BOOST_REQUIRE(eval(te, 4) == 16);
  }

  {
    std::string lt_e = "n < 3";
    BOOST_REQUIRE(eval(lt_e, 2) == 1);
    BOOST_REQUIRE(eval(lt_e, 3) == 0);
    BOOST_REQUIRE(eval(lt_e, 4) == 0);

    std::string lte_e = "n <= 3";
    BOOST_REQUIRE(eval(lte_e, 2) == 1);
    BOOST_REQUIRE(eval(lte_e, 3) == 1);
    BOOST_REQUIRE(eval(lte_e, 4) == 0);

    std::string gt_e = "n > 3";
    BOOST_REQUIRE(eval(gt_e, 2) == 0);
    BOOST_REQUIRE(eval(gt_e, 3) == 0);
    BOOST_REQUIRE(eval(gt_e, 4) == 1);

    std::string gte_e = "n >= 3";
    BOOST_REQUIRE(eval(gte_e, 2) == 0);
    BOOST_REQUIRE(eval(gte_e, 3) == 1);
    BOOST_REQUIRE(eval(gte_e, 4) == 1);

    std::string combined = 
      lt_e + " || " + lte_e + " && " + gt_e + " && " + gte_e;
    BOOST_REQUIRE(eval(combined, 2) == 1);
    BOOST_REQUIRE(eval(combined, 3) == 0);
    BOOST_REQUIRE(eval(combined, 4) == 0);
  }

  {
    std::string e = "2 + 3 * n";
    BOOST_REQUIRE(eval(e, 2) == 8);
  }

  {
    std::string e = "2 < 3 == n";
    BOOST_REQUIRE(eval(e, 2) == 0);

    e += " || 1";
    BOOST_REQUIRE(eval(e, 2) == 1);

    e += " ? 2 : 4";
    BOOST_REQUIRE(eval(e, 2) == 2);
  }
}

BOOST_AUTO_TEST_CASE( cexpression_basic_languagesTest )
{
  //Polish language expression
  {
    std::string e 
      = "n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2";
    BOOST_REQUIRE(eval(e, 1) == 0);
    BOOST_REQUIRE(eval(e, 3) == 1);
    BOOST_REQUIRE(eval(e, 22) == 1);
    BOOST_REQUIRE(eval(e, 6) == 2);
    BOOST_REQUIRE(eval(e, 30) == 2);
  }

  //Japanese/Vietnamese/Korean language expression
  {
    std::string e = "0";
    BOOST_REQUIRE(eval(e, 0) == 0);
    BOOST_REQUIRE(eval(e, 1) == 0);
    BOOST_REQUIRE(eval(e, 3) == 0);
    BOOST_REQUIRE(eval(e, 22) == 0);
  }

  //English, German, Dutch, Swedish, Danish, Norwegian, Faroese,
  //Spanish, Portuguese, Italian, Bulgarian 
  //Greek
  //Finnish, Estonian, Hungarian 
  //Hebrew
  //Esperanto
  //Turkish
  //language expression
  {
    std::string e = "n != 1";
    BOOST_REQUIRE(eval(e, 0) == 1);
    BOOST_REQUIRE(eval(e, 1) == 0);
    BOOST_REQUIRE(eval(e, 3) == 1);
    BOOST_REQUIRE(eval(e, 22) == 1);
  }

  //Brazilian Portuguese, French language expression
  {
    std::string e = "n > 1";
    BOOST_REQUIRE(eval(e, 0) == 0);
    BOOST_REQUIRE(eval(e, 1) == 0);
    BOOST_REQUIRE(eval(e, 3) == 1);
    BOOST_REQUIRE(eval(e, 22) == 1);
  }
  
  //Russian, Ukrainian, Serbian, Croatian language expression
  {
    std::string e = "n%10==1 && n%100!=11 ? 0 :"
      "n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2";

    BOOST_REQUIRE(eval(e, 0) == 2);
    BOOST_REQUIRE(eval(e, 1) == 0);
    BOOST_REQUIRE(eval(e, 2) == 1);
    BOOST_REQUIRE(eval(e, 3) == 1);
    BOOST_REQUIRE(eval(e, 4) == 1);

    BOOST_REQUIRE(eval(e, 11) == 2);
    BOOST_REQUIRE(eval(e, 12) == 2);
    BOOST_REQUIRE(eval(e, 13) == 2);
    BOOST_REQUIRE(eval(e, 14) == 2);
    
    BOOST_REQUIRE(eval(e, 211) == 2);
    BOOST_REQUIRE(eval(e, 212) == 2);
    BOOST_REQUIRE(eval(e, 213) == 2);
    BOOST_REQUIRE(eval(e, 214) == 2);

    BOOST_REQUIRE(eval(e, 201) == 0);
    BOOST_REQUIRE(eval(e, 202) == 1);
    BOOST_REQUIRE(eval(e, 203) == 1);
    BOOST_REQUIRE(eval(e, 204) == 1);
  }
}