Skip to content

Commit fd54bf0

Browse files
ZimmerAmr-c
authored andcommitted
typescript codegen shortname() plus test
1 parent 37e0ad8 commit fd54bf0

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

schema_salad/typescript/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ export {
22
loadDocument,
33
loadDocumentByString,
44
ValidationException,
5+
shortName,
56
${generated_class_imports}
67
} from './util/Internal'
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { assert } from 'chai'
2+
import { shortName } from '../util/Internal'
3+
4+
describe('Test Utilities', () => {
5+
describe('shortName', () => {
6+
it('test1', async () => {
7+
assert.equal(
8+
shortName('file:/Users/jdidion/projects/cwlScala/target/test-classes/CommandLineTools/conformance/#anon_enum_inside_array_inside_schemadef.cwl/first/user_type_2/species/homo_sapiens'),
9+
'homo_sapiens'
10+
)
11+
}),
12+
it('test2', async () => {
13+
assert.equal(
14+
shortName('file:///home/michael/cwljava/src/test/resources/org/w3id/cwl/cwl1_2/utils/valid_anon_enum_inside_array_inside_schemadef.cwl#vcf2maf_params/ncbi_build/GRCh37'),
15+
'GRCh37'
16+
)
17+
}),
18+
it('test3', async () => {
19+
assert.equal(
20+
shortName('http://example.com/foo'), 'foo'
21+
)
22+
}),
23+
it('test4', async () => {
24+
assert.equal(
25+
shortName('http://example.com/#bar'), 'bar'
26+
)
27+
}),
28+
it('test5', async () => {
29+
assert.equal(
30+
shortName('http://example.com/foo/bar'), 'bar'
31+
)
32+
}),
33+
it('test6', async () => {
34+
assert.equal(
35+
shortName('http://example.com/foo#bar'), 'bar'
36+
)
37+
}),
38+
it('test7', async () => {
39+
assert.equal(
40+
shortName('http://example.com/#foo/bar'), 'bar'
41+
)
42+
}),
43+
it('test8', async () => {
44+
assert.equal(
45+
shortName('http://example.com/foo#bar/baz'), 'baz'
46+
)
47+
})
48+
})
49+
})

schema_salad/typescript/util/Saveable.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,21 @@ export function prefixUrl (url: string, namespaces: Dictionary<string>): string
9898
}
9999
return url
100100
}
101+
102+
/**
103+
* Compute the shortname of a fully qualified identifer.
104+
* See https://w3id.org/cwl/v1.2/SchemaSalad.html#Short_names.
105+
*
106+
*/
107+
export function shortName (inputId: string): string {
108+
const parsedId = URI.parse(inputId)
109+
if (parsedId.fragment != null) {
110+
const fragmentSplit = parsedId.fragment.split('/')
111+
return fragmentSplit[fragmentSplit.length - 1]
112+
} else if (parsedId.path != null) {
113+
const pathSplit = parsedId.path.split('/')
114+
return pathSplit[pathSplit.length - 1]
115+
} else {
116+
return inputId
117+
}
118+
}

0 commit comments

Comments
 (0)