Skip to content

Commit 5c7289c

Browse files
committed
Add CI workflow for build, test, and type checking; enhance README and XmlElement tests
1 parent 277a485 commit 5c7289c

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

.github/workflows/build.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Build, test and typecheck
2+
3+
on: push
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout repository
10+
uses: actions/checkout@v4
11+
- uses: oven-sh/setup-bun@v2
12+
with:
13+
bun-version: 1.2
14+
- name: Install dependencies
15+
run: bun install
16+
- name: Test
17+
run: bun test --coverage
18+
- name: Typecheck
19+
run: bun typecheck

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ dist
102102

103103
# vuepress v2.x temp and cache directory
104104
.temp
105-
.cache
106105

107106
# Docusaurus cache and generated files
108107
.docusaurus
@@ -129,4 +128,5 @@ dist
129128
.yarn/install-state.gz
130129
.pnp.*
131130

132-
*.js
131+
.idea
132+
*.js

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ If you have an XML file that you want to read, modify, and write back, this libr
1313
- Retains attribute quotes (single or double) and whitespace before and after the attribute name
1414
- Retains XML processing instructions (including the XML declaration)
1515
- Retains CDATA sections
16+
17+
## Development
18+
19+
This project is written in Typescript and uses Bun.
20+
21+
```bash
22+
bun install
23+
bun test
24+
```

model/xmlElement.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, expect, it } from 'bun:test';
22
import { XmlElement } from './xmlElement';
33
import { XmlText } from './xmlText';
4+
import { XmlAttribute } from './xmlAttribute';
45

56
describe('XmlElement', () => {
67
describe('addElement', () => {
@@ -80,4 +81,15 @@ describe('XmlElement', () => {
8081
});
8182
});
8283
});
84+
describe('getAttributeValue', () => {
85+
it('should return the value of the attribute', () => {
86+
const element = new XmlElement('test', [new XmlAttribute('key', 'value &')]);
87+
expect(element.getAttributeValue('key')).toBe('value &');
88+
});
89+
90+
it('should return undefined if the attribute does not exist', () => {
91+
const element = new XmlElement('test');
92+
expect(element.getAttributeValue('key')).toBeUndefined();
93+
});
94+
});
8395
});

model/xmlElement.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ export class XmlElement extends XmlNode {
8181
this.joinTextNodes();
8282
}
8383

84+
getAttribute(name: string): XmlAttribute | undefined {
85+
return this.attributes.find((attr) => attr.name === name);
86+
}
87+
88+
/** returns unescaped attribute value or undefined if not found */
89+
getAttributeValue(name: string): string | undefined {
90+
return this.getAttribute(name)?.unescapeValue();
91+
}
92+
8493
toString(): string {
8594
let openTag = `<${this.tagName}`;
8695
for (const attr of this.attributes) {

0 commit comments

Comments
 (0)