|
4 | 4 |
|
5 | 5 | import { beforeEach, describe, it } from "jsr:@std/testing/bdd";
|
6 | 6 | import { ScopeInfoBuilder } from "./builder.ts";
|
7 |
| -import { assertEquals, assertStrictEquals } from "jsr:@std/assert"; |
| 7 | +import { |
| 8 | + assertEquals, |
| 9 | + assertNotStrictEquals, |
| 10 | + assertStrictEquals, |
| 11 | +} from "jsr:@std/assert"; |
8 | 12 |
|
9 | 13 | describe("ScopeInfoBuilder", () => {
|
10 | 14 | let builder: ScopeInfoBuilder;
|
@@ -126,4 +130,49 @@ describe("ScopeInfoBuilder", () => {
|
126 | 130 | builder.endRange(0, 20);
|
127 | 131 | });
|
128 | 132 | });
|
| 133 | + |
| 134 | + describe("currentScope", () => { |
| 135 | + it("returns 'null' when no scope is on the stack", () => { |
| 136 | + assertStrictEquals(builder.currentScope(), null); |
| 137 | + }); |
| 138 | + |
| 139 | + it("returns the currently open scope (top-level)", () => { |
| 140 | + builder.startScope(0, 0); |
| 141 | + |
| 142 | + assertNotStrictEquals(builder.currentScope(), null); |
| 143 | + }); |
| 144 | + |
| 145 | + it("returns the currently open scope (nested)", () => { |
| 146 | + builder.startScope(0, 0).startScope(10, 0); |
| 147 | + |
| 148 | + assertEquals(builder.currentScope()?.start, { line: 10, column: 0 }); |
| 149 | + }); |
| 150 | + }); |
| 151 | + |
| 152 | + describe("lastScope", () => { |
| 153 | + it("returns 'null' when no scope was closed yet", () => { |
| 154 | + assertStrictEquals(builder.lastScope(), null); |
| 155 | + }); |
| 156 | + |
| 157 | + it("returns the last closed scope (top-level)", () => { |
| 158 | + builder.startScope(0, 0).endScope(10, 0); |
| 159 | + |
| 160 | + assertNotStrictEquals(builder.lastScope(), null); |
| 161 | + }); |
| 162 | + |
| 163 | + it("returns the last closed scope (nested)", () => { |
| 164 | + builder.startScope(0, 0).startScope(10, 0).endScope(20, 0); |
| 165 | + |
| 166 | + assertEquals(builder.lastScope()?.start, { line: 10, column: 0 }); |
| 167 | + }); |
| 168 | + |
| 169 | + it("returns the last closed scope after starting new ones", () => { |
| 170 | + builder.startScope(0, 0).startScope(10, 0).endScope(20, 0).startScope( |
| 171 | + 30, |
| 172 | + 0, |
| 173 | + ); |
| 174 | + |
| 175 | + assertEquals(builder.lastScope()?.start, { line: 10, column: 0 }); |
| 176 | + }); |
| 177 | + }); |
129 | 178 | });
|
0 commit comments