{"size": 2522, "ext": "js", "max_stars_repo_path": "test/api.js", "max_stars_repo_name": "BuggyOrg/codegen", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/api.js", "max_issues_repo_name": "BuggyOrg/codegen", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/api.js", "max_forks_repo_name": "BuggyOrg/codegen", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 45.0357142857, "max_line_length": 130, "alphanum_fraction": 0.655035686}
/* global describe, it */

import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import * as graphAPI from '@buggyorg/graphtools'
import * as api from '../src/api.js'
import {packLanguages} from '../src/language'

chai.use(chaiAsPromised)

const expect = chai.expect

describe('API methods', () => {
  describe('Source code generation', () => {
    it('returns a string', () => {
      return expect(packLanguages('./test/fixtures/emptyLang')
      .then((emptyLang) => api.generateExecutable(graphAPI.empty(), emptyLang, {}))).to.eventually.be.a('string')
    })

    it('returns a the correct contents', () => {
      return expect(packLanguages('./test/fixtures/emptyLang')
      .then((emptyLang) => api.generateExecutable(graphAPI.empty(), emptyLang, {}))).to.eventually.equal('main')
    })

    it('can process templates', () => {
      return expect(packLanguages('./test/fixtures/simpleTemplate')
      .then((tLang) => api.generateExecutable(graphAPI.empty(), tLang, {}))).to.eventually.equal('templates')
    })

    it('Supports extending languages', () => {
      return expect(packLanguages(['./test/fixtures/lang2', './test/fixtures/lang1'])
      .then((eLang) => api.generateExecutable(graphAPI.empty(), eLang, {}))).to.eventually.equal('t1-extended-content;t2-content')
    })

    it('Language features can be enabled dependent on their context', () => {
      return expect(packLanguages(['./test/fixtures/deplang2', './test/fixtures/lang1'])
      .then((eLang) => api.generateExecutable(graphAPI.empty(), eLang, {}))).to.eventually.equal('t1-dependent;t2-content')
    })

    it('Creates code for atomics correctly', () => {
      const graph = graphAPI.addNode(
        {componentId: 'atomic', ports: [{port: 'a', kind: 'input', type: 'Number'}], atomic: true}, graphAPI.empty())
      return expect(packLanguages('./test/fixtures/atomics')
      .then((eLang) => api.generateExecutable(graph, eLang, {}))).to.eventually.equal('<atomic-code>')
    })

    it('Can resolve base templates', () =>
      expect(packLanguages(['./test/fixtures/deplang3', './test/fixtures/lang3'])
      .then((eLang) => api.generateExecutable(graphAPI.empty(), eLang, {}))).to.eventually.equal('base:main'))

    it('Can resolve base templates multiple times', () =>
      expect(packLanguages(['./test/fixtures/deplang4', './test/fixtures/deplang3', './test/fixtures/lang3'])
      .then((eLang) => api.generateExecutable(graphAPI.empty(), eLang, {}))).to.eventually.equal('base4:base:main'))
  })
})
