馃寠 A GraphQL implementation in Gleam
at main 2.0 kB view raw
1/// Tests for GraphQL Value types 2/// 3/// GraphQL spec Section 2 - Language 4/// Values can be: Null, Int, Float, String, Boolean, Enum, List, Object 5import gleeunit/should 6import swell/value.{Boolean, Enum, Float, Int, List, Null, Object, String} 7 8pub fn null_value_test() { 9 let val = Null 10 should.equal(val, Null) 11} 12 13pub fn int_value_test() { 14 let val = Int(42) 15 should.equal(val, Int(42)) 16} 17 18pub fn float_value_test() { 19 let val = Float(3.14) 20 should.equal(val, Float(3.14)) 21} 22 23pub fn string_value_test() { 24 let val = String("hello") 25 should.equal(val, String("hello")) 26} 27 28pub fn boolean_true_value_test() { 29 let val = Boolean(True) 30 should.equal(val, Boolean(True)) 31} 32 33pub fn boolean_false_value_test() { 34 let val = Boolean(False) 35 should.equal(val, Boolean(False)) 36} 37 38pub fn enum_value_test() { 39 let val = Enum("ACTIVE") 40 should.equal(val, Enum("ACTIVE")) 41} 42 43pub fn empty_list_value_test() { 44 let val = List([]) 45 should.equal(val, List([])) 46} 47 48pub fn list_of_ints_test() { 49 let val = List([Int(1), Int(2), Int(3)]) 50 should.equal(val, List([Int(1), Int(2), Int(3)])) 51} 52 53pub fn nested_list_test() { 54 let val = List([List([Int(1), Int(2)]), List([Int(3), Int(4)])]) 55 should.equal(val, List([List([Int(1), Int(2)]), List([Int(3), Int(4)])])) 56} 57 58pub fn empty_object_test() { 59 let val = Object([]) 60 should.equal(val, Object([])) 61} 62 63pub fn simple_object_test() { 64 let val = Object([#("name", String("Alice")), #("age", Int(30))]) 65 should.equal(val, Object([#("name", String("Alice")), #("age", Int(30))])) 66} 67 68pub fn nested_object_test() { 69 let val = 70 Object([ 71 #("user", Object([#("name", String("Bob")), #("active", Boolean(True))])), 72 #("count", Int(5)), 73 ]) 74 75 should.equal( 76 val, 77 Object([ 78 #("user", Object([#("name", String("Bob")), #("active", Boolean(True))])), 79 #("count", Int(5)), 80 ]), 81 ) 82} 83 84pub fn mixed_types_list_test() { 85 let val = List([String("hello"), Int(42), Boolean(True), Null]) 86 should.equal(val, List([String("hello"), Int(42), Boolean(True), Null])) 87}