1 module nodes.node_slot; 2 3 import fluid; 4 5 @safe: 6 7 @("NodeSlot can be empty") 8 unittest { 9 10 auto slot = nodeSlot!Node(); 11 auto root = testSpace(nullTheme, slot); 12 13 assert(slot.value is null); 14 15 root.drawAndAssert( 16 slot.doesNotDrawChildren(), 17 ); 18 19 } 20 21 @("NodeSlot can carry a child") 22 unittest { 23 24 auto content = label("Hello, World!"); 25 auto slot = nodeSlot!Label(content); 26 auto root = testSpace(nullTheme, slot); 27 28 root.drawAndAssert( 29 content.draws(), 30 ); 31 root.drawAndAssert( 32 slot.drawsChild(content), 33 ); 34 35 } 36 37 @("NodeSlot can change content") 38 unittest { 39 40 auto slot1 = nodeSlot!Label(label("Hello, ")); 41 auto slot2 = nodeSlot!Label(); 42 auto root = testSpace(nullTheme, slot1, slot2); 43 44 root.drawAndAssert( 45 slot1.drawsChild(slot1.value), 46 slot2.doesNotDrawChildren(), 47 ); 48 49 slot2 = label("World!"); 50 51 auto value1 = slot1.value; 52 auto value2 = slot2.value; 53 54 root.drawAndAssert( 55 slot1.drawsChild(value1), 56 slot2.drawsChild(value2), 57 ); 58 59 slot1.swapSlots(slot2); 60 61 root.drawAndAssert( 62 slot1.drawsChild(value2), 63 slot2.drawsChild(value1), 64 ); 65 66 } 67 68 @("NodeSlot content can be cleared") 69 unittest { 70 71 auto slot = nodeSlot!Label(label("Woo!")); 72 auto root = testSpace(slot); 73 74 root.drawAndAssert( 75 slot.drawsChild(slot.value), 76 ); 77 78 slot.clear(); 79 80 root.drawAndAssert( 81 slot.doesNotDrawChildren(), 82 ); 83 84 }