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

     1  package lists_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/lmorg/murex/test"
     7  )
     8  
     9  func TestMatchPositive(t *testing.T) {
    10  	tests := []test.MurexTest{
    11  		{
    12  			Block:  `ja: [Monday..Wednesday] -> match s`,
    13  			Stdout: `["Tuesday","Wednesday"]`,
    14  		},
    15  		{
    16  			Block:  `ja: [Monday..Wednesday] -> !match s`,
    17  			Stdout: `["Monday"]`,
    18  		},
    19  		{
    20  			Block:  `ja: [Monday..Wednesday] -> !match S`,
    21  			Stdout: `["Monday","Tuesday","Wednesday"]`,
    22  		},
    23  	}
    24  
    25  	test.RunMurexTests(tests, t)
    26  }
    27  
    28  func TestMatchNegative(t *testing.T) {
    29  	tests := []test.MurexTest{
    30  		{
    31  			Block:   `ja: [Monday..Wednesday] -> match S`,
    32  			Stderr:  "no data returned\n",
    33  			ExitNum: 1,
    34  		},
    35  		{
    36  			Block:   `ja: [Monday..Wednesday] -> !match day`,
    37  			Stderr:  "no data returned\n",
    38  			ExitNum: 1,
    39  		},
    40  	}
    41  
    42  	test.RunMurexTestsRx(tests, t)
    43  }
    44  
    45  func TestRegexpMatchPositive(t *testing.T) {
    46  	tests := []test.MurexTest{
    47  		{
    48  			Block:  `ja: [Monday..Wednesday] -> regexp %(m/s/)`,
    49  			Stdout: `["Tuesday","Wednesday"]`,
    50  		},
    51  		{
    52  			Block:  `ja: [Monday..Wednesday] -> regexp %(m.s.)`,
    53  			Stdout: `["Tuesday","Wednesday"]`,
    54  		},
    55  	}
    56  
    57  	test.RunMurexTests(tests, t)
    58  }
    59  
    60  func TestRegexpMatchNegative(t *testing.T) {
    61  	tests := []test.MurexTest{
    62  		{
    63  			Block:   `ja: [Monday..Wednesday] -> regexp %(m/S/)`,
    64  			Stderr:  "nothing matched",
    65  			ExitNum: 1,
    66  		},
    67  		{
    68  			Block:   `ja: [Monday..Wednesday] -> regexp %(m.S.)`,
    69  			Stderr:  "nothing matched",
    70  			ExitNum: 1,
    71  		},
    72  	}
    73  
    74  	test.RunMurexTestsRx(tests, t)
    75  }
    76  
    77  func TestRegexpMatchBangPositive(t *testing.T) {
    78  	tests := []test.MurexTest{
    79  		{
    80  			Block:  `ja: [Monday..Wednesday] -> !regexp %(m/s/)`,
    81  			Stdout: `["Monday"]`,
    82  		},
    83  		{
    84  			Block:  `ja: [Monday..Wednesday] -> !regexp %(m/S/)`,
    85  			Stdout: `["Monday","Tuesday","Wednesday"]`,
    86  		},
    87  		{
    88  			Block:  `ja: [Monday..Wednesday] -> !regexp %(m.s.)`,
    89  			Stdout: `["Monday"]`,
    90  		},
    91  		{
    92  			Block:  `ja: [Monday..Wednesday] -> !regexp %(m.S.)`,
    93  			Stdout: `["Monday","Tuesday","Wednesday"]`,
    94  		},
    95  	}
    96  
    97  	test.RunMurexTests(tests, t)
    98  }
    99  
   100  func TestRegexpMatchBangNegative(t *testing.T) {
   101  	tests := []test.MurexTest{
   102  		{
   103  			Block:   `ja: [Monday..Wednesday] -> !regexp %(m.day.)`,
   104  			Stderr:  "nothing matched",
   105  			ExitNum: 1,
   106  		},
   107  	}
   108  
   109  	test.RunMurexTestsRx(tests, t)
   110  }
   111  
   112  func TestRegexpSubstitutePositive(t *testing.T) {
   113  	tests := []test.MurexTest{
   114  		{
   115  			Block:  `ja: [Monday..Wednesday] -> regexp %(s/s/5/)`,
   116  			Stdout: `["Monday","Tue5day","Wedne5day"]`,
   117  		},
   118  		{
   119  			Block:  `ja: [Monday..Wednesday] -> regexp %(s/S/5/)`,
   120  			Stdout: `["Monday","Tuesday","Wednesday"]`,
   121  		},
   122  		{
   123  			Block:  `ja: [Monday..Wednesday] -> regexp %(s.day.night.)`,
   124  			Stdout: `["Monnight","Tuesnight","Wednesnight"]`,
   125  		},
   126  		{
   127  			Block:  `ja: [Monday..Wednesday] -> regexp s/day/`,
   128  			Stdout: `["Mon","Tues","Wednes"]`,
   129  		},
   130  	}
   131  
   132  	test.RunMurexTests(tests, t)
   133  }
   134  
   135  func TestRegexpSubstituteNegative(t *testing.T) {
   136  	tests := []test.MurexTest{
   137  		{
   138  			Block:   `ja: [Monday..Wednesday] -> regexp s/day`,
   139  			Stderr:  "invalid regex: too few parameters",
   140  			ExitNum: 1,
   141  		},
   142  	}
   143  
   144  	test.RunMurexTestsRx(tests, t)
   145  }
   146  
   147  func TestRegexpSubstituteBangNegative(t *testing.T) {
   148  	tests := []test.MurexTest{
   149  		{
   150  			Block:   `ja: [Monday..Wednesday] -> !regexp %(s/s/5/)`,
   151  			Stderr:  "Error in `!regexp`",
   152  			ExitNum: 1,
   153  		},
   154  	}
   155  
   156  	test.RunMurexTestsRx(tests, t)
   157  }
   158  
   159  func TestRegexpFindSubmatchPositive(t *testing.T) {
   160  	tests := []test.MurexTest{
   161  		{
   162  			Block:  `ja: [Monday..Wednesday] -> regexp %(f/(day)/)`,
   163  			Stdout: `["day","day","day"]`,
   164  		},
   165  		{
   166  			Block:  `ja: [Monday..Wednesday] -> regexp %(f.(day).)`,
   167  			Stdout: `["day","day","day"]`,
   168  		},
   169  		{
   170  			Block:  `ja: [Monday..Wednesday] -> regexp %(f/(s)/)`,
   171  			Stdout: `["s","s"]`,
   172  		},
   173  		{
   174  			Block:  `ja: [Monday..Wednesday] -> regexp %(f/Tue(s)/)`,
   175  			Stdout: `["s"]`,
   176  		},
   177  	}
   178  
   179  	test.RunMurexTests(tests, t)
   180  }
   181  
   182  func TestRegexpFindSubmatchNegative(t *testing.T) {
   183  	tests := []test.MurexTest{
   184  		{
   185  			Block:   `ja: [Monday..Wednesday] -> regexp %(f/S/)`,
   186  			Stderr:  "no data returned\n",
   187  			ExitNum: 1,
   188  		},
   189  		{
   190  			Block:   `ja: [Monday..Wednesday] -> regexp %(f/s/)`,
   191  			Stderr:  "no data returned\n",
   192  			ExitNum: 1,
   193  		},
   194  	}
   195  
   196  	test.RunMurexTestsRx(tests, t)
   197  }
   198  
   199  func TestRegexpFindSubmatchBang(t *testing.T) {
   200  	tests := []test.MurexTest{
   201  		{
   202  			Block:   `ja: [Monday..Wednesday] -> !regexp %(f/(day)/)`,
   203  			Stderr:  "Error in `!regexp`",
   204  			ExitNum: 1,
   205  		},
   206  	}
   207  
   208  	test.RunMurexTestsRx(tests, t)
   209  }
   210  
   211  func TestRegexpErrors(t *testing.T) {
   212  	tests := []test.MurexTest{
   213  		{
   214  			Block:   `ja: [Monday..Wednesday] -> regexp`,
   215  			Stderr:  "Error",
   216  			ExitNum: 1,
   217  		},
   218  		{
   219  			Block:   `ja: [Monday..Wednesday] -> regexp s`,
   220  			Stderr:  "Error",
   221  			ExitNum: 1,
   222  		},
   223  		{
   224  			Block:   `ja: [Monday..Wednesday] -> regexp f`,
   225  			Stderr:  "Error",
   226  			ExitNum: 1,
   227  		},
   228  		{
   229  			Block:   `ja: [Monday..Wednesday] -> regexp m`,
   230  			Stderr:  "Error",
   231  			ExitNum: 1,
   232  		},
   233  		{
   234  			Block:   `ja: [Monday..Wednesday] -> regexp b/bob/`,
   235  			Stderr:  "Error",
   236  			ExitNum: 1,
   237  		},
   238  		{
   239  			Block:   `ja: [Monday..Wednesday] -> regexp m\\bob\\`,
   240  			Stderr:  "Error",
   241  			ExitNum: 1,
   242  		},
   243  		{
   244  			Block:   `ja: [Monday..Wednesday] -> regexp m{bob}`,
   245  			Stderr:  "Error",
   246  			ExitNum: 1,
   247  		},
   248  	}
   249  
   250  	test.RunMurexTestsRx(tests, t)
   251  }