Compare commits
No commits in common. "84bda96276f6f349af7d113fa22944ea5e532b40" and "f553396eee29e1e0820624345e5d23dc3471a4a4" have entirely different histories.
84bda96276
...
f553396eee
@ -1,5 +1,5 @@
|
|||||||
export class Element {
|
export class Element {
|
||||||
private _name = '';
|
public name: string;
|
||||||
protected parent_name: string;
|
protected parent_name: string;
|
||||||
|
|
||||||
public get full_name (): string {
|
public get full_name (): string {
|
||||||
@ -8,30 +8,15 @@ export class Element {
|
|||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get name (): string {
|
|
||||||
return this._name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set name (val: string) {
|
|
||||||
const new_name = val.replace (/[^a-z0-9]/giu, '')
|
|
||||||
.replace (/^[0-9]+/iu, '');
|
|
||||||
if (new_name === '')
|
|
||||||
throw new Error ('invalid name specified');
|
|
||||||
this._name = new_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get parent (): string {
|
public get parent (): string {
|
||||||
return this.parent_name;
|
return this.parent_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public constructor (name: string, parent = '') {
|
public constructor (name: string, parent = '') {
|
||||||
<<<<<<< HEAD
|
|
||||||
=======
|
|
||||||
const regex = /^[a-z_][a-z_0-9]+$/iu;
|
const regex = /^[a-z_][a-z_0-9]+$/iu;
|
||||||
|
|
||||||
if (!regex.test (name))
|
if (!regex.test (name))
|
||||||
throw new Error ('invalid name specified');
|
throw new Error ('invalid name specified');
|
||||||
>>>>>>> f553396eee29e1e0820624345e5d23dc3471a4a4
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.parent_name = parent;
|
this.parent_name = parent;
|
||||||
}
|
}
|
||||||
|
14
test/Node.ts
14
test/Node.ts
@ -53,23 +53,9 @@ test ('serialize table', (t) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test ('adhere to naming convention', (t) => {
|
test ('adhere to naming convention', (t) => {
|
||||||
const n = new Node ('invalid.name', 'parent');
|
|
||||||
t.is (n.name, 'invalidname');
|
|
||||||
});
|
|
||||||
|
|
||||||
test ('throw on invalid name', (t) => {
|
|
||||||
t.throws (() => {
|
t.throws (() => {
|
||||||
<<<<<<< HEAD
|
|
||||||
const n = new Node ('564#+-.,/@', 'parent');
|
|
||||||
=======
|
|
||||||
const n = new Node ('invalid.name', 'parent');
|
const n = new Node ('invalid.name', 'parent');
|
||||||
|
|
||||||
>>>>>>> f553396eee29e1e0820624345e5d23dc3471a4a4
|
|
||||||
return n.toString ();
|
return n.toString ();
|
||||||
}, { message: 'invalid name specified' });
|
}, { message: 'invalid name specified' });
|
||||||
});
|
});
|
||||||
|
|
||||||
test ('leave numbers after the first letter', (t) => {
|
|
||||||
const n = new Node ('i123nvalid.name', 'parent');
|
|
||||||
t.is (n.name, 'i123nvalidname');
|
|
||||||
});
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user