github.com/urso/go-structform@v0.0.2/sftest/cases.go (about)

     1  package sftest
     2  
     3  import structform "github.com/urso/go-structform"
     4  
     5  var Samples = concatSamples(
     6  	SamplesPrimitives,
     7  	SamplesArr,
     8  	SamplesObj,
     9  	SamplesCombinations,
    10  )
    11  
    12  var SamplesPrimitives = []Recording{
    13  	// simple primitives
    14  	{NilRec{}},       // "null"
    15  	{BoolRec{true}},  // "true"
    16  	{BoolRec{false}}, // "false"
    17  	{StringRec{"test"}},
    18  	{StringRec{`test with " being special`}},
    19  	{StringRec{""}},
    20  
    21  	// int types
    22  	{IntRec{8}},
    23  	{IntRec{42}},
    24  	{IntRec{100}},
    25  	{IntRec{-90}},
    26  	{IntRec{12345678}},
    27  	{IntRec{-12345678}},
    28  	{Int8Rec{8}},
    29  	{Int8Rec{42}},
    30  	{Int8Rec{100}},
    31  	{Int8Rec{-90}},
    32  	{Int16Rec{8}},
    33  	{Int16Rec{42}},
    34  	{Int16Rec{100}},
    35  	{Int16Rec{-90}},
    36  	{Int16Rec{500}},
    37  	{Int16Rec{-500}},
    38  	{Int32Rec{8}},
    39  	{Int32Rec{42}},
    40  	{Int32Rec{100}},
    41  	{Int32Rec{-90}},
    42  	{Int32Rec{500}},
    43  	{Int32Rec{-500}},
    44  	{Int32Rec{12345678}},
    45  	{Int32Rec{-12345678}},
    46  	{Int64Rec{8}},
    47  	{Int64Rec{42}},
    48  	{Int64Rec{100}},
    49  	{Int64Rec{-90}},
    50  	{Int64Rec{500}},
    51  	{Int64Rec{-500}},
    52  	{Int64Rec{123456781234}},
    53  	{Int64Rec{-123456781234}},
    54  
    55  	// uint types
    56  	{UintRec{8}},
    57  	{UintRec{42}},
    58  	{UintRec{100}},
    59  	{UintRec{12345678}},
    60  	{Uint8Rec{8}},
    61  	{Uint8Rec{42}},
    62  	{Uint8Rec{100}},
    63  	{ByteRec{8}},
    64  	{ByteRec{42}},
    65  	{ByteRec{100}},
    66  	{Uint16Rec{8}},
    67  	{Uint16Rec{42}},
    68  	{Uint16Rec{100}},
    69  	{Uint16Rec{500}},
    70  	{Uint32Rec{8}},
    71  	{Uint32Rec{42}},
    72  	{Uint32Rec{100}},
    73  	{Uint32Rec{500}},
    74  	{Uint32Rec{12345678}},
    75  	{Uint64Rec{8}},
    76  	{Uint64Rec{42}},
    77  	{Uint64Rec{100}},
    78  	{Uint64Rec{500}},
    79  	{Uint64Rec{123456781234}},
    80  
    81  	// float types
    82  	{Float32Rec{3.14}},
    83  	{Float32Rec{-3.14}},
    84  	{Float64Rec{3.14}},
    85  	{Float64Rec{-3.14}},
    86  }
    87  
    88  var SamplesArr = []Recording{
    89  	// empty arrays `[]`
    90  	Arr(0, structform.AnyType),
    91  	Arr(-1, structform.AnyType),
    92  
    93  	// nested empty array `[[]]`
    94  	Arr(1, structform.AnyType,
    95  		Arr(0, structform.AnyType),
    96  	),
    97  	Arr(-1, structform.AnyType,
    98  		Arr(0, structform.AnyType),
    99  	),
   100  	Arr(-1, structform.AnyType,
   101  		Arr(-1, structform.AnyType),
   102  	),
   103  
   104  	// array with arbitrary values
   105  	Arr(-1, structform.AnyType,
   106  		NilRec{},
   107  		BoolRec{true},
   108  		BoolRec{false},
   109  		IntRec{1},
   110  		Int64Rec{12345678910},
   111  		Float32Rec{3.14},
   112  		Float64Rec{7e+09},
   113  		StringRec{"test"},
   114  	),
   115  	Arr(2, structform.AnyType,
   116  		Int8Rec{1},
   117  		BoolRec{true},
   118  	),
   119  	{
   120  		Int8ArrRec{[]int8{1, 2, 3}},
   121  	},
   122  	{
   123  		StringArrRec{[]string{"a", "b", "c"}},
   124  	},
   125  }
   126  
   127  var SamplesObj = []Recording{
   128  	// empty object '{}'
   129  	Obj(-1, structform.AnyType),
   130  	Obj(0, structform.AnyType),
   131  
   132  	Obj(-1, structform.AnyType,
   133  		"a", NilRec{},
   134  	),
   135  
   136  	// objects
   137  	Obj(-1, structform.AnyType,
   138  		"a", StringRec{"test"}),
   139  	Obj(1, structform.StringType,
   140  		"a", StringRec{"test"}),
   141  	Obj(-1, structform.AnyType,
   142  		"a", BoolRec{true},
   143  		"b", BoolRec{false},
   144  	),
   145  	Obj(2, structform.AnyType,
   146  		"a", BoolRec{true},
   147  		"b", BoolRec{false},
   148  	),
   149  	Obj(-1, structform.BoolType,
   150  		"a", BoolRec{true},
   151  		"b", BoolRec{false},
   152  	),
   153  	Obj(2, structform.BoolType,
   154  		"a", BoolRec{true},
   155  		"b", BoolRec{false},
   156  	),
   157  	Obj(-1, structform.AnyType,
   158  		"a", UintRec{1},
   159  		"b", Float64Rec{3.14},
   160  		"c", StringRec{"test"},
   161  		"d", BoolRec{true},
   162  	),
   163  
   164  	// typed objects
   165  	{
   166  		StringObjRec{map[string]string{
   167  			"a": "test1",
   168  			"b": "test2",
   169  			"c": "test3",
   170  		}},
   171  	},
   172  	{
   173  		UintObjRec{map[string]uint{
   174  			"a": 1,
   175  			"b": 2,
   176  			"c": 3,
   177  		}},
   178  	},
   179  }
   180  
   181  var SamplesCombinations = []Recording{
   182  	// objects in array
   183  	Arr(-1, structform.AnyType,
   184  		Obj(-1, structform.AnyType)),
   185  	Arr(1, structform.AnyType,
   186  		Obj(0, structform.AnyType)),
   187  	Arr(-1, structform.AnyType,
   188  		Obj(-1, structform.AnyType,
   189  			"a", IntRec{-1},
   190  		),
   191  		Obj(1, structform.UintType,
   192  			"a", UintRec{1},
   193  		),
   194  	),
   195  	Arr(2, structform.AnyType,
   196  		Obj(-1, structform.AnyType,
   197  			"a", IntRec{-1},
   198  		),
   199  		Obj(1, structform.UintType,
   200  			"a", UintRec{1},
   201  		),
   202  	),
   203  
   204  	// array in object
   205  	Obj(-1, structform.AnyType,
   206  		"a", Arr(3, structform.IntType,
   207  			IntRec{1}, IntRec{2}, IntRec{3}),
   208  	),
   209  	Obj(1, structform.AnyType,
   210  		"a", Arr(3, structform.IntType,
   211  			IntRec{1}, IntRec{2}, IntRec{3}),
   212  	),
   213  	Obj(1, structform.AnyType,
   214  		"a", Int8ArrRec{[]int8{1, 2, 3}},
   215  	),
   216  }