github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/lang/expressions/exp07_test.go (about)

     1  package expressions
     2  
     3  import "testing"
     4  
     5  func TestExpEqualToStrict(t *testing.T) {
     6  	tests := []expressionTestT{
     7  		{
     8  			Expression: `"foobar" == "foobar"`,
     9  			Expected:   true,
    10  		},
    11  		{
    12  			Expression: `"foo" == "bar"`,
    13  			Expected:   false,
    14  		},
    15  		///
    16  		{
    17  			Expression: `1 == 1`,
    18  			Expected:   true,
    19  		},
    20  		{
    21  			Expression: `1 == 2`,
    22  			Expected:   false,
    23  		},
    24  		///
    25  		{
    26  			Expression: `1 == "1"`,
    27  			Error:      true,
    28  		},
    29  		{
    30  			Expression: `1 == "2"`,
    31  			Error:      true,
    32  		},
    33  		///
    34  		{
    35  			Expression: `$variable == ""`,
    36  			Error:      true,
    37  		},
    38  		{
    39  			Expression: `$variable == null`,
    40  			Expected:   true,
    41  		},
    42  	}
    43  
    44  	testExpression(t, tests, true)
    45  }
    46  
    47  func TestExpEqualToWeak(t *testing.T) {
    48  	tests := []expressionTestT{
    49  		{
    50  			Expression: `"foobar" == "foobar"`,
    51  			Expected:   true,
    52  		},
    53  		{
    54  			Expression: `"foo" == "bar"`,
    55  			Expected:   false,
    56  		},
    57  		///
    58  		{
    59  			Expression: `1 == 1`,
    60  			Expected:   true,
    61  		},
    62  		{
    63  			Expression: `1 == 2`,
    64  			Expected:   false,
    65  		},
    66  		///
    67  		{
    68  			Expression: `1 == "1"`,
    69  			Expected:   true,
    70  		},
    71  		{
    72  			Expression: `1 == "2"`,
    73  			Expected:   false,
    74  		},
    75  		///
    76  		{
    77  			Expression: `1.0 == "1"`,
    78  			Expected:   true,
    79  		},
    80  		{
    81  			Expression: `1.0 == "2"`,
    82  			Expected:   false,
    83  		},
    84  		///
    85  		{
    86  			Expression: `$variable == ""`,
    87  			Expected:   true,
    88  		},
    89  		{
    90  			Expression: `$variable == null`,
    91  			Expected:   true,
    92  		},
    93  	}
    94  
    95  	testExpression(t, tests, false)
    96  }
    97  
    98  func TestExpNotEqualToStrong(t *testing.T) {
    99  	tests := []expressionTestT{
   100  		{
   101  			Expression: `"foobar" != "foobar"`,
   102  			Expected:   false,
   103  		},
   104  		{
   105  			Expression: `"foo" != "bar"`,
   106  			Expected:   true,
   107  		},
   108  		///
   109  		{
   110  			Expression: `1 != 1`,
   111  			Expected:   false,
   112  		},
   113  		{
   114  			Expression: `1 != 2`,
   115  			Expected:   true,
   116  		},
   117  		///
   118  		{
   119  			Expression: `1 != "1"`,
   120  			Error:      true,
   121  		},
   122  		{
   123  			Expression: `1 != "2"`,
   124  			Error:      true,
   125  		},
   126  	}
   127  
   128  	testExpression(t, tests, true)
   129  }
   130  
   131  func TestExpNotEqualToWeak(t *testing.T) {
   132  	tests := []expressionTestT{
   133  		{
   134  			Expression: `"foobar" != "foobar"`,
   135  			Expected:   false,
   136  		},
   137  		{
   138  			Expression: `"foo" != "bar"`,
   139  			Expected:   true,
   140  		},
   141  		///
   142  		{
   143  			Expression: `1 != 1`,
   144  			Expected:   false,
   145  		},
   146  		{
   147  			Expression: `1 != 2`,
   148  			Expected:   true,
   149  		},
   150  		///
   151  		{
   152  			Expression: `1 != "1"`,
   153  			Expected:   false,
   154  		},
   155  		{
   156  			Expression: `1 != "2"`,
   157  			Expected:   true,
   158  		},
   159  		///
   160  		{
   161  			Expression: `1.0 != "1"`,
   162  			Expected:   false,
   163  		},
   164  		{
   165  			Expression: `1.0 != "2"`,
   166  			Expected:   true,
   167  		},
   168  	}
   169  
   170  	testExpression(t, tests, false)
   171  }
   172  
   173  func TestExpLike(t *testing.T) {
   174  	tests := []expressionTestT{
   175  		{
   176  			Expression: `"foobar" ~~ "foobar"`,
   177  			Expected:   true,
   178  		},
   179  		{
   180  			Expression: `"foobar" ~~ "FOOBAR"`,
   181  			Expected:   true,
   182  		},
   183  		{
   184  			Expression: `"foo" ~~ "bar"`,
   185  			Expected:   false,
   186  		},
   187  		///
   188  		{
   189  			Expression: `1 ~~ 1`,
   190  			Expected:   true,
   191  		},
   192  		{
   193  			Expression: `1 ~~ 2`,
   194  			Expected:   false,
   195  		},
   196  		///
   197  		{
   198  			Expression: `1 ~~ "1"`,
   199  			Expected:   true,
   200  		},
   201  		{
   202  			Expression: `1 ~~ "2"`,
   203  			Expected:   false,
   204  		},
   205  		///
   206  		{
   207  			Expression: `(1==1) ~~ "true"`,
   208  			Expected:   true,
   209  		},
   210  		{
   211  			Expression: `(1==1) ~~ "false"`,
   212  			Expected:   false,
   213  		},
   214  	}
   215  
   216  	testExpression(t, tests, true)
   217  }
   218  
   219  func TestExpNotLike(t *testing.T) {
   220  	tests := []expressionTestT{
   221  		{
   222  			Expression: `"foobar" !! "foobar"`,
   223  			Expected:   false,
   224  		},
   225  		{
   226  			Expression: `"foobar" !! "FOOBAR"`,
   227  			Expected:   false,
   228  		},
   229  		{
   230  			Expression: `"foo" !! "bar"`,
   231  			Expected:   true,
   232  		},
   233  		///
   234  		{
   235  			Expression: `1 !! 1`,
   236  			Expected:   false,
   237  		},
   238  		{
   239  			Expression: `1 !! 2`,
   240  			Expected:   true,
   241  		},
   242  		///
   243  		{
   244  			Expression: `1 !! "1"`,
   245  			Expected:   false,
   246  		},
   247  		{
   248  			Expression: `1 !! "2"`,
   249  			Expected:   true,
   250  		},
   251  		///
   252  		{
   253  			Expression: `(1==1) !! "true"`,
   254  			Expected:   false,
   255  		},
   256  		{
   257  			Expression: `(1==1) !! "false"`,
   258  			Expected:   true,
   259  		},
   260  	}
   261  
   262  	testExpression(t, tests, true)
   263  }
   264  
   265  func TestExpRegexp(t *testing.T) {
   266  	tests := []expressionTestT{
   267  		{
   268  			Expression: `"foobar" =~ "foobar"`,
   269  			Expected:   true,
   270  		},
   271  		{
   272  			Expression: `"foo" =~ "bar"`,
   273  			Expected:   false,
   274  		},
   275  		///
   276  		{
   277  			Expression: `1 =~ 1`,
   278  			Error:      true,
   279  		},
   280  		{
   281  			Expression: `1 =~ 2`,
   282  			Error:      true,
   283  		},
   284  		///
   285  		{
   286  			Expression: `1 =~ "1"`,
   287  			Error:      true,
   288  		},
   289  		{
   290  			Expression: `1 =~ "2"`,
   291  			Error:      true,
   292  		},
   293  		///
   294  		{
   295  			Expression: `"foobar" =~ "foo"`,
   296  			Expected:   true,
   297  		},
   298  		{
   299  			Expression: `"foobar" =~ 'foo$'`,
   300  			Expected:   false,
   301  		},
   302  	}
   303  
   304  	testExpression(t, tests, true)
   305  }
   306  
   307  func TestExpNotRegexp(t *testing.T) {
   308  	tests := []expressionTestT{
   309  		{
   310  			Expression: `"foobar" !~ "foobar"`,
   311  			Expected:   false,
   312  		},
   313  		{
   314  			Expression: `"foo" !~ "bar"`,
   315  			Expected:   true,
   316  		},
   317  		///
   318  		{
   319  			Expression: `1 !~ 1`,
   320  			Error:      true,
   321  		},
   322  		{
   323  			Expression: `1 !~ 2`,
   324  			Error:      true,
   325  		},
   326  		///
   327  		{
   328  			Expression: `1 !~ "1"`,
   329  			Error:      true,
   330  		},
   331  		{
   332  			Expression: `1 !~ "2"`,
   333  			Error:      true,
   334  		},
   335  		///
   336  		{
   337  			Expression: `"foobar" !~ "foo"`,
   338  			Expected:   false,
   339  		},
   340  		{
   341  			Expression: `"foobar" !~ 'foo$'`,
   342  			Expected:   true,
   343  		},
   344  	}
   345  
   346  	testExpression(t, tests, true)
   347  }