import &StandardImport, {} &path, fs: &fsExtra

global.CaffeineMcTestHelper = class CaffeineMcTestHelper extends BaseObject
  @classProperty testLog: []

  @log: (str) => @testLog.push str
  @reset: =>
    WorkingCache.resetWorkingCache()
    CaffeineMc.SourceRoots._resetSourceRoots()
    @testLog = []

  @testFiles:
    alpha:  "/" + path.join :test :files :SourceRoots :DotCaffeineRoot :HurlockAlpha.caf
    beta:   "/" + path.join :test :files :SourceRoots :DotCaffeineRoot :SubAwesome :BetaRelease.caf

  @mockFileSystem:     => fs.setMockFileStructure @initialFs
  @unmockFileSystem:   => fs.unmockFs()

  @initialFs:
    test: files:
      MyCompiler.caffeine:
        """
          |coffee-script:
            {Parser} = require 'babel-bridge'
            {compactFlatten} = require 'art-standard-lib'

            class MyParser extends Parser
              @rule
                root:
                  pattern: 'word+ _?'
                  node: toJs: -> (w.toWord() for w in @words).join ', '

                word:
                  pattern: '_? wordRegExp'
                  node: toWord: -> @wordRegExp.toString()

                wordRegExp: /[^\s]+/
                _: /\s+/

            @compiler = compile: (source) ->
              myParser = new MyParser
              root = myParser.parse source
              compiled: js: "module.exports = '\#{root.toJs()}'"

          this is how it should work!

      SourceRoots:
        DotCaffeineRoot:
          SubAwesome: BetaRelease.caf: "" b.caf ran
          caffeine-mc.config.caf:
            """
              |CoffeeScript
                CoffeeScript = require 'coffee-script'
                path = require 'path'
                {formattedInspect} = require 'art-standard-lib'
                CaffeineMcTestHelper.log "caffeine-mc.config.caf loaded"

                @compiler = class ItWorkedCompiler
                  @version: "1.2.3"
                  @compile: (source, options) ->
                    {sourceFile, mySpecialConfig} = options
                    CaffeineMcTestHelper.log "caffeine-mc.config.caf custom compiler used on: \#{path.basename sourceFile}, mySpecialConfig: \#{formattedInspect mySpecialConfig}"
                    CoffeeScript.compile source, options

              CaffeineMcTestHelper.log "caffeine-mc.config.caf ran"
              module.exports = mySpecialConfig: "worked!"

          HurlockAlpha.caf: "" a.caf ran

        DotCaffeineRootPeer.caf: ""
