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

     1  package lists
     2  
     3  import (
     4  	"testing"
     5  
     6  	_ "github.com/lmorg/murex/builtins/types/string"
     7  	"github.com/lmorg/murex/lang/types"
     8  	"github.com/lmorg/murex/test"
     9  )
    10  
    11  func TestJsplit(t *testing.T) {
    12  	test.RunMethodTest(t,
    13  		cmdJsplit, "jsplit",
    14  		`hello world`,
    15  		types.String,
    16  		[]string{" "},
    17  		`["hello","world"]`,
    18  		nil,
    19  	)
    20  }
    21  
    22  func TestJsplitCrLF1(t *testing.T) {
    23  	test.RunMethodTest(t,
    24  		cmdJsplit, "jsplit",
    25  		"hello world\n",
    26  		types.String,
    27  		[]string{" "},
    28  		`["hello","world"]`,
    29  		nil,
    30  	)
    31  }
    32  
    33  func TestJsplitCrLF2(t *testing.T) {
    34  	test.RunMethodTest(t,
    35  		cmdJsplit, "jsplit",
    36  		"hello world\r\n",
    37  		types.String,
    38  		[]string{" "},
    39  		`["hello","world"]`,
    40  		nil,
    41  	)
    42  }
    43  
    44  func TestJsplitCrLF3(t *testing.T) {
    45  	test.RunMethodTest(t,
    46  		cmdJsplit, "jsplit",
    47  		"hello world\n\n",
    48  		types.String,
    49  		[]string{" "},
    50  		`["hello","world"]`,
    51  		nil,
    52  	)
    53  }
    54  
    55  func TestJsplitCrLF4(t *testing.T) {
    56  	test.RunMethodTest(t,
    57  		cmdJsplit, "jsplit",
    58  		"hello world\r\n\r\n",
    59  		types.String,
    60  		[]string{" "},
    61  		`["hello","world"]`,
    62  		nil,
    63  	)
    64  }
    65  
    66  func TestJsplitCrLF5(t *testing.T) {
    67  	test.RunMethodTest(t,
    68  		cmdJsplit, "jsplit",
    69  		"hello\nworld\n",
    70  		types.String,
    71  		[]string{"\n"},
    72  		`["hello","world"]`,
    73  		nil,
    74  	)
    75  }
    76  
    77  func TestJsplitCrLF6(t *testing.T) {
    78  	test.RunMethodTest(t,
    79  		cmdJsplit, "jsplit",
    80  		"hello\r\nworld\r\n",
    81  		types.String,
    82  		[]string{"\n"},
    83  		`["hello","world"]`,
    84  		nil,
    85  	)
    86  }
    87  
    88  func TestJsplitCrLF7(t *testing.T) {
    89  	test.RunMethodTest(t,
    90  		cmdJsplit, "jsplit",
    91  		"hello\n\nworld\n\n",
    92  		types.String,
    93  		[]string{"\n"},
    94  		`["hello","","world"]`,
    95  		nil,
    96  	)
    97  }
    98  
    99  func TestJsplitCrLF8(t *testing.T) {
   100  	test.RunMethodTest(t,
   101  		cmdJsplit, "jsplit",
   102  		"hello\r\n\r\nworld\r\n\r\n",
   103  		types.String,
   104  		[]string{"\n"},
   105  		`["hello","","world"]`,
   106  		nil,
   107  	)
   108  }