# test.coordination/core/analyzers/source.analyzer.test.ts

> 46 lines of code and 0 definitions.

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

Listed in [test.coordination/core/analyzers](https://banes-lab.com/api/source/testing/test.coordination/core/analyzers.md), after [test.coordination/core/analyzers/snapshot.analyzer.test.ts](https://banes-lab.com/source/testing/test.coordination/core/analyzers/snapshot.analyzer.test.ts.md) and before [test.coordination/core/analyzers/vocabulary.analyzer.test.ts](https://banes-lab.com/source/testing/test.coordination/core/analyzers/vocabulary.analyzer.test.ts.md).

## Contained in

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

## Source

```typescript
import {
    braceDelta,
    codeMask,
    identifiersIn,
    isWordChar,
    matchesAt,
    memberKey,
    memberValue,
    spacesFrom,
    wordFrom,
} from "coordination-surface/tools/core/analyzers/source.analyzer.ts";
import { describe, it } from "vitest";
import assert from "node:assert/strict";

describe("isWordChar and codeMask", () => {
    it("count the dollar sign as a word character, and mark only the characters outside quotes as code", () => {
        assert.equal(isWordChar("$"), true);
        assert.equal(isWordChar("-"), false);
        assert.deepEqual(codeMask('a"b"c'), [true, false, false, false, true]);
        assert.deepEqual(codeMask(String.raw`"\""x`), [false, false, false, false, true]);
    });
});

describe("matchesAt, spacesFrom and wordFrom", () => {
    it("match a whole word only, and read past spaces and across one word", () => {
        assert.equal(matchesAt("foo bar", 4, "bar"), true);
        assert.equal(matchesAt("foobar", 3, "bar"), false);
        assert.equal(matchesAt("bar_x", 0, "bar"), false);
        assert.equal(spacesFrom("a   b", 1), 4);
        assert.equal(wordFrom("ab$c d", 0), "ab$c");
    });
});

describe("identifiersIn", () => {
    it("lists the identifiers of a line of code, skipping the words inside strings", () => {
        assert.deepEqual(identifiersIn('const x = "y z"; w'), ["const", "x", "w"]);
    });
});

describe("memberKey, memberValue and braceDelta", () => {
    it("read a letters-only object member, and count how far a line opens or closes braces", () => {
        assert.equal(memberKey("kind: frozen,"), "kind");
        assert.equal(memberValue("kind: frozen,"), "frozen");
        assert.equal(memberValue("kind: 'frozen'"), "");
        assert.equal(memberKey("two words: x"), "");
        assert.equal(memberValue("no colon"), "");
        assert.equal(braceDelta("{ { }"), 1);
        assert.equal(braceDelta("}"), -1);
    });
});
```
