Skip to content

Commit

Permalink
Merge pull request #14 from bdalpe/feature/regex
Browse files Browse the repository at this point in the history
Add regexes
  • Loading branch information
bdalpe authored Oct 2, 2024
2 parents 8c91815 + a1dee2c commit 0097c7c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/__tests__/__snapshots__/regex.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Regexex > should be written to the file 1`] = `
"test:
lib: test
regex: /test/
"
`;
27 changes: 27 additions & 0 deletions lib/__tests__/regex.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {it, expect, vi, beforeEach, describe} from 'vitest';
import {vol} from 'memfs'
import {Cribl} from "../index";
import {Regex} from "../objects";

vi.mock('node:fs');
vi.mock('node:fs/promises');

let cribl: Cribl;

beforeEach(() => {
// reset the state of in-memory fs
vol.reset()

cribl = new Cribl({outdir: '/tmp'});
});

describe('Regexex', () => {
it('should be written to the file', () => {
new Regex(cribl, 'test', {lib: 'test', regex: '/test/'});
cribl.synth();

const volume = vol.toJSON();
expect(Object.keys(volume)).toEqual(['/tmp/local/cribl/regexes.yml']);
expect(volume['/tmp/local/cribl/regexes.yml']).toMatchSnapshot();
});
});
1 change: 1 addition & 0 deletions lib/objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export * from './license';
export * from './sample';
export * from './scripts';
export * from './variable';
export * from './regex'
export * from './parsers';
31 changes: 31 additions & 0 deletions lib/objects/regex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {ConfigConstruct} from "../config";
import {Construct} from "constructs";
import Registry from "../registry";

export interface RegexProps {
lib: string;

description?: string;

regex: string;

sampleData?: string;

tags?: string;
}

export class Regex extends ConfigConstruct {
constructor(scope: Construct, id: string, props: RegexProps) {
super(scope, id, props);
}

get kind() {
return 'regexes';
}

static dump(config: ConfigConstruct[]): Record<string, unknown> {
return Object.fromEntries(config.map(c => [c.node.id, c.config]));
}
}

Registry.register('regexes', Regex);

0 comments on commit 0097c7c

Please sign in to comment.