1 module tests.ut.ctaa; 2 3 import unit_threaded; 4 import reggae.ctaa; 5 6 7 void testEmpty() { 8 auto aa = AssocList!(string, string)(); 9 aa.get("foo", "ohnoes").shouldEqual("ohnoes"); 10 } 11 12 void testConversion() { 13 auto aa = assocList([assocEntry("foo", "true")]); 14 aa.get("foo", false).shouldBeTrue(); 15 aa.get("bar", false).shouldBeFalse(); 16 aa.get("bar", true).shouldBeTrue(); 17 } 18 19 void testOpIndex() { 20 static struct MyInt { int i; } 21 auto aa = assocList([assocEntry("one", MyInt(1)), assocEntry("two", MyInt(2))]); 22 aa["one"].shouldEqual(MyInt(1)); 23 aa["two"].shouldEqual(MyInt(2)); 24 } 25 26 27 void testStringToStrings() { 28 auto aa = assocList([assocEntry("includes", ["-I$project/headers"]), 29 assocEntry("flags", ["-m64", "-fPIC", "-O3"])]); 30 aa["flags"].shouldEqual(["-m64", "-fPIC", "-O3"]); 31 string[] emp; 32 aa.get("flags", emp).shouldEqual(["-m64", "-fPIC", "-O3"]); 33 } 34 35 void testKeys() { 36 auto aa = assocListT("includes", ["-I$project/headers"], 37 "flags", ["-m64", "-fPIC", "-O3"]); 38 aa.keys.shouldEqual(["includes", "flags"]); 39 } 40 41 42 void testIn() { 43 auto aa = assocListT("foo", 3, "bar", 5); 44 ("foo" in aa).shouldBeTrue; 45 ("bar" in aa).shouldBeTrue; 46 ("asda" in aa).shouldBeFalse; 47 } 48 49 @("Convert to runtime AA") 50 unittest { 51 assocListT("foo", "bar", "toto", "baz").toAA.shouldEqual( 52 ["foo": "bar", "toto": "baz"]); 53 assocListT("foo", 3, "toto", 5).toAA.shouldEqual( 54 ["foo": 3, "toto": 5]); 55 56 } 57 58 @("Convert from runtime AA") 59 unittest { 60 fromAA(["foo": "bar"]).shouldEqual(assocListT("foo", "bar")); 61 fromAA(["foo": 5]).shouldEqual(assocListT("foo", 5)); 62 }