def test_export(self): for value in ( 1, 2, "aaaa", 2.0, { 1: 2 }, [1, 2, 3], ["hello", decimal.Decimal("1.23")], wl.Foo, wl.Foo(2, wl.Context.Internal), ): self.serialize_compare(value, export(value, target_format="wxf")) self.assertEqual( export(Association(enumerate("abc")), target_format="wxf"), export( wl.Association(*(wl.Rule(i, v) for i, v in enumerate("abc"))), target_format="wxf", ), ) self.assertEqual( export(wlexpr("2+2"), target_format="wxf"), export(wl.ToExpression("2+2"), target_format="wxf"), ) self.assertEqual( export(wl.Foo(wlexpr("2+2"), 1, 2), target_format="wxf"), export(wl.Foo(wl.ToExpression("2+2"), 1, 2), target_format="wxf"), )
def test_input_form(self): self.compare(wlexpr('<|"2" -> 2|>'), b'(<|"2" -> 2|>)') self.compare( wl.Foo(2, wlexpr("#foo &")(wlexpr('<|"foo" -> 2|>'))), b'Foo[2, (#foo &)[(<|"foo" -> 2|>)]]', )