def test_can_use_only_one_embedded_property(self): source = "-- ClassName: LocalScript" script = rbxmx.ScriptElement(source=source) properties = script.get_embedded_properties() assert properties["ClassName"] == "LocalScript"
def test_does_not_detect_regular_comments_as_embedded_properties(self): source = "-- This is a comment" script = rbxmx.ScriptElement(source=source) properties = script.get_embedded_properties() assert not properties
def test_can_have_source(self): script = rbxmx.ScriptElement("Script", source="print(\"Hello, World!\")") expected_xml = "<ProtectedString name=\"Source\">print(\"Hello, " \ "World!\")</ProtectedString>" assert rbxmx.tostring(script.source) == expected_xml
def test_can_attempt_to_override_without_embedded_properties(self): source = dedent("""\ local function hello() return "Hello, World!" end return hello""") script = rbxmx.ScriptElement(source=source) script.use_embedded_properties()
def test_can_get_embedded_properties(self): source = dedent("""\ -- Name: HelloWorld -- ClassName: LocalScript print("Hello, World!")""") script = rbxmx.ScriptElement(source=source) properties = script.get_embedded_properties() assert properties["Name"] == "HelloWorld" assert properties["ClassName"] == "LocalScript"
def test_does_not_error_without_first_comment(self): source = dedent("""\ local function hello() return "Hello, World!" end return hello""") script = rbxmx.ScriptElement(source=source) comment = script.get_first_comment() assert comment is None
def test_is_overriding_with_embedded_properties(self): source = dedent("""\ -- Name: HelloWorld -- ClassName: LocalScript print("Hello, World!")""") script = rbxmx.ScriptElement(name="SampleScript", source=source) assert script.name.text == "SampleScript" script.use_embedded_properties() assert script.name.text == "HelloWorld"
def test_can_match_first_comment(self): comment = dedent("""\ -- Name: SomeScript -- ClassName: LocalScript print("Hello, World!")""") expected_output = dedent("""\ -- Name: SomeScript -- ClassName: LocalScript""") script = rbxmx.ScriptElement(source=comment) first_comment = script.get_first_comment() assert first_comment == expected_output
def test_does_not_match_block_comments(self): """ Right now, comment matching is only done to inline comments for simplicity. If a more sophisticated pattern is implemented to pick up block comments, this test can be removed. """ comment = dedent("""\ --[[ Hello, World! --]]""") script = rbxmx.ScriptElement(source=comment) first_comment = script.get_first_comment() assert first_comment is None
def test_fails_graceully_for_property_that_doesnt_exist(self): source = "-- NonExistentProperty: true" script = rbxmx.ScriptElement(source=source) script.use_embedded_properties()
def test_does_not_error_without_source(self): script = rbxmx.ScriptElement() # No `source` argument comment = script.get_first_comment() assert comment is None
def test_can_have_varied_class_name(self): for script_class in ["Script", "LocalScript", "ModuleScript"]: script = rbxmx.ScriptElement(script_class) assert script.element.get("class") == script_class
def test_source_can_be_blank(self): script = rbxmx.ScriptElement("Script", source=None) expected_xml = "<ProtectedString name=\"Source\"></ProtectedString>" assert rbxmx.tostring(script.source) == expected_xml
def test_disabled_is_converted_properly(self): script = rbxmx.ScriptElement("Script", disabled=True) assert script.disabled.text == "true"