Skip to content

Commit

Permalink
Add serialize function to stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
tekknolagi committed Nov 22, 2023
1 parent f3e2d87 commit 7b131aa
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions scrapscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,15 @@ def test_stdlib_quote_pipe(self) -> None:
def test_stdlib_quote_reverse_pipe(self) -> None:
self.assertEqual(self._run("$$quote <| 3 + 4"), Binop(BinopKind.ADD, Int(3), Int(4)))

def test_stdlib_serialize(self) -> None:
self.assertEqual(self._run("$$serialize 3", STDLIB), Bytes(value=b"d4:type3:Int5:valuei3ee"))

def test_stdlib_serialize_expr(self) -> None:
self.assertEqual(
self._run("(1+2) |> $$quote |> $$serialize", STDLIB),
Bytes(value=b"d4:leftd4:type3:Int5:valuei1ee2:op3:ADD5:rightd4:type3:Int5:valuei2ee4:type5:Binope"),
)


class BencodeTests(unittest.TestCase):
def test_bencode_int(self) -> None:
Expand Down Expand Up @@ -1999,6 +2008,7 @@ def jsondecode(obj: Object) -> Object:
"$$add": NativeFunction(lambda x: NativeFunction(lambda y: Int(unpack_int(x) + unpack_int(y)))),
"$$fetch": NativeFunction(fetch),
"$$jsondecode": NativeFunction(jsondecode),
"$$serialize": NativeFunction(lambda obj: Bytes(serialize(obj))),
}


Expand Down

0 comments on commit 7b131aa

Please sign in to comment.