Skip to content

Commit

Permalink
Implement Fusion async file system (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
breck7 authored Nov 29, 2024
1 parent 104e025 commit 81eb3cb
Show file tree
Hide file tree
Showing 12 changed files with 793 additions and 335 deletions.
57 changes: 38 additions & 19 deletions fusion/Fusion.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/env ts-node

const { Particle } = require("../products/Particle.js")
const { Fusion } = require("../products/Fusion.js")
const { Fusion, FusionFile } = require("../products/Fusion.js")
const { TestRacer } = require("../products/TestRacer.js")
const path = require("path")
import { particlesTypes } from "../products/particlesTypes"

const testParticles: particlesTypes.testParticles = {}

testParticles.disk = equal => {
testParticles.disk = async equal => {
const tfs = new Fusion()
// Arrange/Act/Assert
equal(tfs.fuseFile(path.join(__dirname, "..", "readme.scroll")).fused.length > 0, true)
const result = await tfs.fuseFile(path.join(__dirname, "..", "readme.scroll"))
equal(result.fused.length > 0, true)
}

const stripImported = (str: string) => {
Expand All @@ -20,7 +20,7 @@ const stripImported = (str: string) => {
return particle.toString()
}

testParticles.inMemory = equal => {
testParticles.inMemory = async equal => {
// Arrange/Act/Assert
const files = {
"/hello": "world",
Expand All @@ -30,43 +30,44 @@ testParticles.inMemory = equal => {
}
const tfs = new Fusion(files)
equal(tfs.dirname("/"), "/")
equal(stripImported(tfs.fuseFile("/main").fused), "world\nciao")
equal(stripImported(tfs.fuseFile("/nested/deep/relative").fused), "world\nciao")
equal(tfs.fuseFile("/main").exists, true)
const mainResult = await tfs.fuseFile("/main")
equal(stripImported(mainResult.fused), "world\nciao")

const relativeResult = await tfs.fuseFile("/nested/deep/relative")
equal(stripImported(relativeResult.fused), "world\nciao")
equal(mainResult.exists, true)
}

testParticles.nonExistant = equal => {
testParticles.nonExistant = async equal => {
// Arrange/Act/Assert
const files = {
"/main": "import env"
}
const tfs = new Fusion(files)
const result = tfs.fuseFile("/main")
const result = await tfs.fuseFile("/main")
equal(stripImported(result.fused), "")
equal(result.exists, false)
}

testParticles.footers = equal => {
testParticles.footers = async equal => {
// Arrange/Act/Assert
const files = {
"/hello.scroll": `headerAndFooter.scroll
title Hello world
This is my content
`,
"/headerAndFooter.scroll": "header.scroll\nfooter.scroll\n footer",
"/header.scroll": "printTitle",
"/footer.scroll": "The end."
}
const tfs = new Fusion(files)
const result = tfs.fuseFile("/hello.scroll")
const result = await tfs.fuseFile("/hello.scroll")
equal(result.fused.includes("This is my content"), true)
equal(result.fused.includes("The end"), false)
equal(result.footers[0], "The end.")
}

testParticles.quickImports = equal => {
testParticles.quickImports = async equal => {
// Arrange/Act/Assert
const files = {
"/hello.scroll": "world",
Expand All @@ -77,11 +78,29 @@ testParticles.quickImports = equal => {
}
const tfs = new Fusion(files)
equal(tfs.dirname("/"), "/")
equal(stripImported(tfs.fuseFile("/nested/a").fused), "ciao")
equal(stripImported(tfs.fuseFile("/main").fused), "world\nciao")
equal(stripImported(tfs.fuseFile("/nested/deep/relative").fused), "world\nciao")

const [aResult, mainResult, relativeResult] = await Promise.all([tfs.fuseFile("/nested/a"), tfs.fuseFile("/main"), tfs.fuseFile("/nested/deep/relative")])

equal(stripImported(aResult.fused), "ciao")
equal(stripImported(mainResult.fused), "world\nciao")
equal(stripImported(relativeResult.fused), "world\nciao")

// FileAPI
// Arrange
const file = new FusionFile(files["/main"], "/main", tfs)
equal(file.fusedCode, undefined)
// Act
await file.fuse()
// Assert
equal(stripImported(file.fusedCode), "world\nciao")
}

/*NODE_JS_ONLY*/ if (!module.parent) TestRacer.testSingleFile(__filename, testParticles)
/*NODE_JS_ONLY*/ if (!module.parent) {
// Update TestRacer to handle async tests
const runTests = async () => {
await TestRacer.testSingleFile(__filename, testParticles)
}
runTests()
}

export { testParticles }
Loading

0 comments on commit 81eb3cb

Please sign in to comment.