-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Lexer support for optional chaining * Parsing and transpile support * Fix optional chaning indexed get and ternary * re-enable failing tests. * Addresses PR items * Remove ?( * Fixes for optional chaining tokens. * Fixes * another optional chain vs ternary test * Add disclaimer to ternary docs * add transpile tests for ?@ and @( * Re-enable simple consequents tests * Fix leading ? for print statements
- Loading branch information
1 parent
06ad68a
commit 4c0658f
Showing
10 changed files
with
449 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import * as sinonImport from 'sinon'; | ||
import * as fsExtra from 'fs-extra'; | ||
import { Program } from '../../Program'; | ||
import { standardizePath as s } from '../../util'; | ||
import { getTestTranspile } from '../../testHelpers.spec'; | ||
|
||
let sinon = sinonImport.createSandbox(); | ||
let tmpPath = s`${process.cwd()}/.tmp`; | ||
let rootDir = s`${tmpPath}/rootDir`; | ||
let stagingFolderPath = s`${tmpPath}/staging`; | ||
|
||
describe('optional chaining', () => { | ||
let program: Program; | ||
const testTranspile = getTestTranspile(() => [program, rootDir]); | ||
|
||
beforeEach(() => { | ||
fsExtra.ensureDirSync(tmpPath); | ||
fsExtra.emptyDirSync(tmpPath); | ||
program = new Program({ | ||
rootDir: rootDir, | ||
stagingFolderPath: stagingFolderPath | ||
}); | ||
}); | ||
afterEach(() => { | ||
sinon.restore(); | ||
fsExtra.ensureDirSync(tmpPath); | ||
fsExtra.emptyDirSync(tmpPath); | ||
program.dispose(); | ||
}); | ||
|
||
it('transpiles ?. properly', () => { | ||
testTranspile(` | ||
sub main() | ||
print m?.value | ||
end sub | ||
`); | ||
}); | ||
|
||
it('transpiles ?[ properly', () => { | ||
testTranspile(` | ||
sub main() | ||
print m?["value"] | ||
end sub | ||
`); | ||
}); | ||
|
||
it(`transpiles '?.[`, () => { | ||
testTranspile(` | ||
sub main() | ||
print m?["value"] | ||
end sub | ||
`); | ||
}); | ||
|
||
it(`transpiles '?@`, () => { | ||
testTranspile(` | ||
sub main() | ||
print xmlThing?@someAttr | ||
end sub | ||
`); | ||
}); | ||
|
||
it(`transpiles '?(`, () => { | ||
testTranspile(` | ||
sub main() | ||
localFunc = sub() | ||
end sub | ||
print localFunc?() | ||
print m.someFunc?() | ||
end sub | ||
`); | ||
}); | ||
|
||
it('transpiles various use cases', () => { | ||
testTranspile(` | ||
print arr?.["0"] | ||
print arr?.value | ||
print assocArray?.[0] | ||
print assocArray?.getName()?.first?.second | ||
print createObject("roByteArray")?.value | ||
print createObject("roByteArray")?["0"] | ||
print createObject("roList")?.value | ||
print createObject("roList")?["0"] | ||
print createObject("roXmlList")?["0"] | ||
print createObject("roDateTime")?.value | ||
print createObject("roDateTime")?.GetTimeZoneOffset | ||
print createObject("roSGNode", "Node")?[0] | ||
print pi?.first?.second | ||
print success?.first?.second | ||
print a.b.xmlThing?@someAttr | ||
print a.b.localFunc?() | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.