# test.coordination/core/transformers/scope.transformer.test.ts

> 18 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-coordination-core-transformers-scope-transformer-test-ts
Source text: https://banes-lab.com/source/testing/test.coordination/core/transformers/scope.transformer.test.ts.txt

Listed in [test.coordination/core/transformers](https://banes-lab.com/api/source/testing/test.coordination/core/transformers.md), after [test.coordination/core/transformers/reference.transformer.test.ts](https://banes-lab.com/source/testing/test.coordination/core/transformers/reference.transformer.test.ts.md) and before [test.coordination/core/transformers/segment.transformer.test.ts](https://banes-lab.com/source/testing/test.coordination/core/transformers/segment.transformer.test.ts.md).

## Contained in

- [test.coordination/core/transformers](https://banes-lab.com/anatomy/testing/folder-testing-test-coordination-core-transformers.md)

## Source

```typescript
import { decodeScope, encodeScope } from "coordination-surface/tools/core/transformers/scope.transformer.ts";
import { describe, it } from "vitest";
import assert from "node:assert/strict";

describe("encodeScope and decodeScope", () => {
    it("keep letters, digits and hyphens, escape every other character, and decode back to the scope", () => {
        const scope = "tools/core ~ a.ts";
        const encoded = encodeScope(scope);
        assert.equal(encodeScope("tools-core"), "tools-core");
        assert.equal(encodeScope("/"), "~22f");
        assert.equal(decodeScope(encoded), scope);
    });

    it("refuses a character the encoding never writes, and an escape cut short", () => {
        assert.equal(decodeScope("a/b"), null);
        assert.equal(decodeScope("~2"), null);
        assert.equal(decodeScope("~0"), null);
        assert.equal(decodeScope("~2zz"), null);
    });
});
```
