github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/core/structs/if_test.go (about)

     1  package structs
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/lmorg/murex/test"
     7  )
     8  
     9  // TestIf tests the `if` builtin
    10  func TestIf(t *testing.T) {
    11  	tests := []test.BooleanTest{
    12  		// --- if / then---
    13  		{
    14  			Block:  "if { true } then { true }",
    15  			Result: true,
    16  		},
    17  		{
    18  			Block:  "if { true } then { false }",
    19  			Result: false,
    20  		},
    21  		{
    22  			Block:  "if { false } then { true }",
    23  			Result: false,
    24  		},
    25  		{
    26  			Block:  "if { false } then { false }",
    27  			Result: false,
    28  		},
    29  
    30  		{
    31  			Block:  "if { true }  { true }",
    32  			Result: true,
    33  		},
    34  		{
    35  			Block:  "if { true }  { false }",
    36  			Result: false,
    37  		},
    38  		{
    39  			Block:  "if { false }  { true }",
    40  			Result: false,
    41  		},
    42  		{
    43  			Block:  "if { false }  { false }",
    44  			Result: false,
    45  		},
    46  		// --- if / then / else ---
    47  		{
    48  			Block:  "if { true } then { true } else { false }",
    49  			Result: true,
    50  		},
    51  		{
    52  			Block:  "if { true } then { false } else { false }",
    53  			Result: false,
    54  		},
    55  		{
    56  			Block:  "if { false } then { true } else { false }",
    57  			Result: false,
    58  		},
    59  		{
    60  			Block:  "if { false } then { false } else { false }",
    61  			Result: false,
    62  		},
    63  
    64  		{
    65  			Block:  "if { true }  { true }  { false }",
    66  			Result: true,
    67  		},
    68  		{
    69  			Block:  "if { true }  { false }  { false }",
    70  			Result: false,
    71  		},
    72  		{
    73  			Block:  "if { false }  { true }  { false }",
    74  			Result: false,
    75  		},
    76  		{
    77  			Block:  "if { false }  { false }  { false }",
    78  			Result: false,
    79  		},
    80  		// ---
    81  		{
    82  			Block:  "if { true } then { true } else { true }",
    83  			Result: true,
    84  		},
    85  		{
    86  			Block:  "if { true } then { false } else { true }",
    87  			Result: false,
    88  		},
    89  		{
    90  			Block:  "if { false } then { true } else { true }",
    91  			Result: true,
    92  		},
    93  		{
    94  			Block:  "if { false } then { false } else { true }",
    95  			Result: true,
    96  		},
    97  
    98  		{
    99  			Block:  "if { true }  { true }  { true }",
   100  			Result: true,
   101  		},
   102  		{
   103  			Block:  "if { true }  { false }  { true }",
   104  			Result: false,
   105  		},
   106  		{
   107  			Block:  "if { false }  { true }  { true }",
   108  			Result: true,
   109  		},
   110  		{
   111  			Block:  "if { false }  { false }  { true }",
   112  			Result: true,
   113  		},
   114  	}
   115  
   116  	test.RunBooleanTests(tests, t)
   117  }
   118  
   119  // TestNotIf tests the `!if` builtin
   120  func TestNotIf(t *testing.T) {
   121  	tests := []test.BooleanTest{
   122  		// --- !if / then---
   123  		{
   124  			Block:  "!if { true } then { true }",
   125  			Result: false,
   126  		},
   127  		{
   128  			Block:  "!if { true } then { false }",
   129  			Result: false,
   130  		},
   131  		{
   132  			Block:  "!if { false } then { true }",
   133  			Result: true,
   134  		},
   135  		{
   136  			Block:  "!if { false } then { false }",
   137  			Result: false,
   138  		},
   139  
   140  		{
   141  			Block:  "!if { true }  { true }",
   142  			Result: false,
   143  		},
   144  		{
   145  			Block:  "!if { true }  { false }",
   146  			Result: false,
   147  		},
   148  		{
   149  			Block:  "!if { false }  { true }",
   150  			Result: true,
   151  		},
   152  		{
   153  			Block:  "!if { false }  { false }",
   154  			Result: false,
   155  		},
   156  		// --- !if / then / else ---
   157  		{
   158  			Block:  "!if { true } then { true } else { false }",
   159  			Result: false,
   160  		},
   161  		{
   162  			Block:  "!if { true } then { false } else { false }",
   163  			Result: false,
   164  		},
   165  		{
   166  			Block:  "!if { false } then { true } else { false }",
   167  			Result: true,
   168  		},
   169  		{
   170  			Block:  "!if { false } then { false } else { false }",
   171  			Result: false,
   172  		},
   173  
   174  		{
   175  			Block:  "!if { true }  { true }  { false }",
   176  			Result: false,
   177  		},
   178  		{
   179  			Block:  "!if { true }  { false }  { false }",
   180  			Result: false,
   181  		},
   182  		{
   183  			Block:  "!if { false }  { true }  { false }",
   184  			Result: true,
   185  		},
   186  		{
   187  			Block:  "!if { false }  { false }  { false }",
   188  			Result: false,
   189  		},
   190  		// ---
   191  		{
   192  			Block:  "!if { true } then { true } else { true }",
   193  			Result: true,
   194  		},
   195  		{
   196  			Block:  "!if { true } then { false } else { true }",
   197  			Result: true,
   198  		},
   199  		{
   200  			Block:  "!if { false } then { true } else { true }",
   201  			Result: true,
   202  		},
   203  		{
   204  			Block:  "!if { false } then { false } else { true }",
   205  			Result: false,
   206  		},
   207  
   208  		{
   209  			Block:  "!if { true }  { true }  { true }",
   210  			Result: true,
   211  		},
   212  		{
   213  			Block:  "!if { true }  { false }  { true }",
   214  			Result: true,
   215  		},
   216  		{
   217  			Block:  "!if { false }  { true }  { true }",
   218  			Result: true,
   219  		},
   220  		{
   221  			Block:  "!if { false }  { false }  { true }",
   222  			Result: false,
   223  		},
   224  	}
   225  
   226  	test.RunBooleanTests(tests, t)
   227  }