|
| 1 | +# pyright: reportPrivateUsage=none |
| 2 | + |
| 3 | +import textwrap |
| 4 | + |
| 5 | +import pytest |
| 6 | +from hexdoc.core.resource import ResourceLocation |
| 7 | +from hexdoc.minecraft.tags import OptionalTagValue, Tag, TagValue |
| 8 | +from hexdoc.utils.types import PydanticOrderedSet |
| 9 | + |
| 10 | + |
| 11 | +@pytest.mark.parametrize( |
| 12 | + ["raw_data", "want_values"], |
| 13 | + [ |
| 14 | + ( |
| 15 | + """\ |
| 16 | + { |
| 17 | + "values": [] |
| 18 | + } |
| 19 | + """, |
| 20 | + [], |
| 21 | + ), |
| 22 | + ( |
| 23 | + """\ |
| 24 | + { |
| 25 | + "values": [ |
| 26 | + "minecraft:stone" |
| 27 | + ] |
| 28 | + } |
| 29 | + """, |
| 30 | + [ |
| 31 | + ResourceLocation("minecraft", "stone"), |
| 32 | + ], |
| 33 | + ), |
| 34 | + ( |
| 35 | + """\ |
| 36 | + { |
| 37 | + "values": [ |
| 38 | + {"id": "minecraft:stone", "required": false} |
| 39 | + ] |
| 40 | + } |
| 41 | + """, |
| 42 | + [ |
| 43 | + OptionalTagValue( |
| 44 | + id=ResourceLocation("minecraft", "stone"), |
| 45 | + required=False, |
| 46 | + ), |
| 47 | + ], |
| 48 | + ), |
| 49 | + ( |
| 50 | + """\ |
| 51 | + { |
| 52 | + "values": [ |
| 53 | + "hextweaks:infusion", |
| 54 | + "hextweaks:nuke_chunk_nowill", |
| 55 | + {"id": "hextweaks:you_like_drinking_potions","required": false} |
| 56 | + ] |
| 57 | + } |
| 58 | + """, |
| 59 | + [ |
| 60 | + ResourceLocation("hextweaks", "infusion"), |
| 61 | + ResourceLocation("hextweaks", "nuke_chunk_nowill"), |
| 62 | + OptionalTagValue( |
| 63 | + id=ResourceLocation("hextweaks", "you_like_drinking_potions"), |
| 64 | + required=False, |
| 65 | + ), |
| 66 | + ], |
| 67 | + ), |
| 68 | + ], |
| 69 | +) |
| 70 | +def test_load_tag_file(raw_data: str, want_values: list[TagValue]): |
| 71 | + tag = Tag._convert( |
| 72 | + registry="", |
| 73 | + raw_data=textwrap.dedent(raw_data), |
| 74 | + ) |
| 75 | + assert list(tag.values) == want_values |
| 76 | + |
| 77 | + |
| 78 | +@pytest.mark.parametrize( |
| 79 | + ["values", "replace", "current_values", "want_data"], |
| 80 | + [ |
| 81 | + ( |
| 82 | + [], |
| 83 | + False, |
| 84 | + None, |
| 85 | + """{"values":[],"replace":false}""", |
| 86 | + ), |
| 87 | + ( |
| 88 | + [], |
| 89 | + False, |
| 90 | + [], |
| 91 | + """{"values":[],"replace":false}""", |
| 92 | + ), |
| 93 | + ( |
| 94 | + [ResourceLocation("minecraft", "stone")], |
| 95 | + False, |
| 96 | + None, |
| 97 | + """{"values":["minecraft:stone"],"replace":false}""", |
| 98 | + ), |
| 99 | + ( |
| 100 | + [], |
| 101 | + False, |
| 102 | + [ResourceLocation("minecraft", "stone")], |
| 103 | + """{"values":["minecraft:stone"],"replace":false}""", |
| 104 | + ), |
| 105 | + ( |
| 106 | + [ResourceLocation("minecraft", "dirt")], |
| 107 | + False, |
| 108 | + [ResourceLocation("minecraft", "stone")], |
| 109 | + """{"values":["minecraft:stone","minecraft:dirt"],"replace":false}""", |
| 110 | + ), |
| 111 | + ( |
| 112 | + [], |
| 113 | + True, |
| 114 | + [ResourceLocation("minecraft", "stone")], |
| 115 | + """{"values":[],"replace":true}""", |
| 116 | + ), |
| 117 | + ( |
| 118 | + [ResourceLocation("minecraft", "dirt")], |
| 119 | + True, |
| 120 | + [ResourceLocation("minecraft", "stone")], |
| 121 | + """{"values":["minecraft:dirt"],"replace":true}""", |
| 122 | + ), |
| 123 | + ( |
| 124 | + [ |
| 125 | + OptionalTagValue( |
| 126 | + id=ResourceLocation("minecraft", "stone"), |
| 127 | + required=True, |
| 128 | + ), |
| 129 | + ], |
| 130 | + False, |
| 131 | + None, |
| 132 | + """{"values":[{"id":"minecraft:stone","required":true}],"replace":false}""", |
| 133 | + ), |
| 134 | + ( |
| 135 | + [ |
| 136 | + OptionalTagValue( |
| 137 | + id=ResourceLocation("minecraft", "stone"), |
| 138 | + required=False, |
| 139 | + ), |
| 140 | + ], |
| 141 | + False, |
| 142 | + None, |
| 143 | + """{"values":[{"id":"minecraft:stone","required":false}],"replace":false}""", |
| 144 | + ), |
| 145 | + ( |
| 146 | + [], |
| 147 | + False, |
| 148 | + [ |
| 149 | + OptionalTagValue( |
| 150 | + id=ResourceLocation("minecraft", "stone"), |
| 151 | + required=True, |
| 152 | + ), |
| 153 | + ], |
| 154 | + """{"values":[{"id":"minecraft:stone","required":true}],"replace":false}""", |
| 155 | + ), |
| 156 | + ( |
| 157 | + [], |
| 158 | + False, |
| 159 | + [ |
| 160 | + OptionalTagValue( |
| 161 | + id=ResourceLocation("minecraft", "stone"), |
| 162 | + required=False, |
| 163 | + ), |
| 164 | + ], |
| 165 | + """{"values":[{"id":"minecraft:stone","required":false}],"replace":false}""", |
| 166 | + ), |
| 167 | + # ( |
| 168 | + # """\ |
| 169 | + # { |
| 170 | + # "values": [ |
| 171 | + # "minecraft:stone" |
| 172 | + # ] |
| 173 | + # } |
| 174 | + # """, |
| 175 | + # [ |
| 176 | + # ResourceLocation("minecraft", "stone"), |
| 177 | + # ], |
| 178 | + # ), |
| 179 | + # ( |
| 180 | + # """\ |
| 181 | + # { |
| 182 | + # "values": [ |
| 183 | + # {"id": "minecraft:stone", "required": false} |
| 184 | + # ] |
| 185 | + # } |
| 186 | + # """, |
| 187 | + # [ |
| 188 | + # OptionalTagValue( |
| 189 | + # id=ResourceLocation("minecraft", "stone"), |
| 190 | + # required=False, |
| 191 | + # ), |
| 192 | + # ], |
| 193 | + # ), |
| 194 | + # ( |
| 195 | + # """\ |
| 196 | + # { |
| 197 | + # "values": [ |
| 198 | + # "hextweaks:infusion", |
| 199 | + # "hextweaks:nuke_chunk_nowill", |
| 200 | + # {"id": "hextweaks:you_like_drinking_potions","required": false} |
| 201 | + # ] |
| 202 | + # } |
| 203 | + # """, |
| 204 | + # [ |
| 205 | + # ResourceLocation("hextweaks", "infusion"), |
| 206 | + # ResourceLocation("hextweaks", "nuke_chunk_nowill"), |
| 207 | + # OptionalTagValue( |
| 208 | + # id=ResourceLocation("hextweaks", "you_like_drinking_potions"), |
| 209 | + # required=False, |
| 210 | + # ), |
| 211 | + # ], |
| 212 | + # ), |
| 213 | + ], |
| 214 | +) |
| 215 | +def test_export_tag( |
| 216 | + values: list[TagValue], |
| 217 | + replace: bool, |
| 218 | + current_values: list[TagValue] | None, |
| 219 | + want_data: str, |
| 220 | +): |
| 221 | + tag = Tag( |
| 222 | + registry="", |
| 223 | + values=PydanticOrderedSet(values), |
| 224 | + replace=replace, |
| 225 | + ) |
| 226 | + |
| 227 | + if current_values is not None: |
| 228 | + current = Tag(registry="", values=PydanticOrderedSet(current_values)) |
| 229 | + else: |
| 230 | + current = None |
| 231 | + |
| 232 | + assert tag._export(current) == want_data |
0 commit comments