diff --git a/lib/modules/manager/bazel-module/context.spec.ts b/lib/modules/manager/bazel-module/context.spec.ts index 2cf9c71a9f54844eaf39812866bd48df0536a952..1ee4ca3c8ab8812112981808b92d8e86716b7364 100644 --- a/lib/modules/manager/bazel-module/context.spec.ts +++ b/lib/modules/manager/bazel-module/context.spec.ts @@ -119,39 +119,25 @@ describe('modules/manager/bazel-module/context', () => { }); }); - describe('.currentRule', () => { - it('returns the record fragment if it is current', () => { - const ctx = new Ctx().startRule('dummy'); - expect(ctx.currentRule).toEqual(fragments.rule('dummy')); - }); - - it('throws if there is no current', () => { - const ctx = new Ctx(); - expect(() => ctx.currentRule).toThrow( - new Error('Requested current, but no value.'), - ); - }); - - it('throws if the current is not a rule fragment', () => { - const ctx = new Ctx().startArray(); - expect(() => ctx.currentRule).toThrow( - new Error('Requested current rule, but does not exist.'), - ); - }); + it('throws on missing current', () => { + const ctx = new Ctx(); + expect(() => ctx.endRule()).toThrow( + new Error('Requested current, but no value.'), + ); }); - describe('.currentArray', () => { - it('returns the array fragment if it is current', () => { - const ctx = new Ctx().startArray(); - expect(ctx.currentArray).toEqual(fragments.array()); - }); + it('throws on unbalanced endRule', () => { + const ctx = new Ctx().startRule('foo').startArray(); + expect(() => ctx.endRule()).toThrow( + new Error('Requested current rule, but does not exist.'), + ); + }); - it('throws if the current is not an array fragment', () => { - const ctx = new Ctx().startRule('dummy'); - expect(() => ctx.currentArray).toThrow( - new Error('Requested current array, but does not exist.'), - ); - }); + it('throws on unbalanced endArray', () => { + const ctx = new Ctx().startArray().startRule('dummy'); + expect(() => ctx.endArray()).toThrow( + new Error('Requested current array, but does not exist.'), + ); }); it('throws if add an attribute without a parent', () => { diff --git a/lib/modules/manager/bazel-module/context.ts b/lib/modules/manager/bazel-module/context.ts index 6ad1a20ea1e49fd814b76e9bb267c58283309332..70342f59ec9728ebbf24b5b0c2836a1d684c7716 100644 --- a/lib/modules/manager/bazel-module/context.ts +++ b/lib/modules/manager/bazel-module/context.ts @@ -48,7 +48,8 @@ export class Ctx implements CtxCompatible { } return c; } - get currentRule(): RuleFragment { + + private get currentRule(): RuleFragment { const current = this.current; if (current.type === 'rule') { return current; @@ -56,7 +57,7 @@ export class Ctx implements CtxCompatible { throw new Error('Requested current rule, but does not exist.'); } - get currentExtensionTag(): ExtensionTagFragment { + private get currentExtensionTag(): ExtensionTagFragment { const current = this.current; if (current.type === 'extensionTag') { return current; @@ -64,7 +65,7 @@ export class Ctx implements CtxCompatible { throw new Error('Requested current extension tag, but does not exist.'); } - get currentArray(): ArrayFragment { + private get currentArray(): ArrayFragment { const current = this.current; if (current.type === 'array') { return current;