With cgo (tree-sitter) the code compressor handles Python and TypeScript too. A successful compression implies the output re-parsed without error, because the compressor validates the re-parse before returning ok.
(t *testing.T)
| 47 | // A successful compression implies the output re-parsed without error, because |
| 48 | // the compressor validates the re-parse before returning ok. |
| 49 | func TestCodeCompressorPython(t *testing.T) { |
| 50 | c := codeCompressor(t) |
| 51 | out, ok := c.Compress([]byte(pySource)) |
| 52 | if !ok { |
| 53 | t.Fatal("expected Python to compress") |
| 54 | } |
| 55 | if len(out) >= len(pySource) { |
| 56 | t.Error("expected Python source to shrink") |
| 57 | } |
| 58 | for _, want := range []string{"def add(a, b):", "class Calc:", "def mul(self, a, b):", "import os"} { |
| 59 | if !bytes.Contains(out, []byte(want)) { |
| 60 | t.Errorf("output must keep %q:\n%s", want, out) |
| 61 | } |
| 62 | } |
| 63 | if bytes.Contains(out, []byte("total = a + b")) { |
| 64 | t.Error("Python body should be elided") |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | func TestCodeCompressorTypeScript(t *testing.T) { |
| 69 | c := codeCompressor(t) |
nothing calls this directly
no test coverage detected