const expect = require('chai').expect
const calculist = require('./main')

describe('basic functionality', () => {
  const listData = {
    text: 'abc [=] sum($items, 0)',
    items: [
      {
        text: 'foo [=>] x | x + 1',
        items: []
      },
      {
        text: 'bar [=] foo(1)',
        items: []
      },
      {
        text: 'baz [:] 1',
        items: []
      }
    ]
  }

  it('is an object', () => {
    expect(calculist).to.be.an('object')
  });

  it('returns a document', () => {
    expect(calculist.new(listData)).to.be.an('object')
  })

  it('returns json', () => {
    let doc = calculist.new(listData)
    expect(doc.toJSON()).to.be.an('object')
  })

  it('calculates correctly', () => {
    let doc = calculist.new(listData)
    expect(doc.valueOf()).to.eq(3)
  })

})

@@ -72,50 +72,8 @@
 ')%0A%0A
-describe('basic functionality', () =%3E %7B%0A  
 cons
@@ -87,18 +87,16 @@
 ata = %7B%0A
-  
   text: 
@@ -123,18 +123,16 @@
  0)',%0A  
- 
- 
 items: %5B
@@ -132,30 +132,26 @@
 tems: %5B%0A    
-  %7B%0A  
+%7B%0A
       text: 
@@ -170,34 +170,32 @@
 %7C x + 1',%0A      
-  
 items: %5B%5D%0A      
@@ -180,34 +180,32 @@
       items: %5B%5D%0A
-  
     %7D,%0A      %7B%0A 
@@ -191,38 +191,34 @@
 : %5B%5D%0A    %7D,%0A    
-  %7B%0A  
+%7B%0A
       text: 'bar
@@ -229,34 +229,32 @@
  foo(1)',%0A      
-  
 items: %5B%5D%0A      
@@ -255,23 +255,17 @@
     
-  
 %7D,%0A    
- 
- 
 %7B%0A
-  
     
@@ -287,26 +287,24 @@
 %5D 1',%0A      
-  
 items: %5B%5D%0A  
@@ -309,21 +309,56 @@
     
-  %7D%0A    %5D%0A  %7D
+%7D%0A  %5D%0A%7D%0A%0Adescribe('basic functionality', () =%3E %7B
 %0A%0A  
@@ -641,24 +641,61 @@
 ect')%0A  %7D)%0A%0A
+%7D)%0A%0Adescribe('calculation', () =%3E %7B%0A%0A
   it('calcul
@@ -699,16 +699,29 @@
 culates 
+plain values 
 correctl
@@ -764,51 +764,1023 @@
 new(
-listData)%0A    expect(doc.valueOf()).to.eq(3
+%7B text: 'foo %5B:%5D 1 + 1' %7D)%0A    expect(doc.valueOf()).to.eq('1 + 1')%0A  %7D)%0A%0A  it('calculates plain expressions correctly', () =%3E %7B%0A    let doc = calculist.new(%7B text: 'foo %5B=%5D 1 + 1' %7D)%0A    expect(doc.valueOf()).to.eq(2)%0A  %7D)%0A%0A  it('calculates functions correctly', () =%3E %7B%0A    let doc = calculist.new(%7B text: 'foo %5B=%3E%5D a, b %7C a + b' %7D)%0A    expect(doc.valueOf()(1, 1)).to.eq(2)%0A  %7D)%0A%0A  it('references variables correctly', () =%3E %7B%0A    let doc = calculist.new(%7B%0A      text: 'foo bar %5B=%5D 5',%0A      items: %5B%0A        %7Btext: 'baz %5B=%5D 2'%7D,%0A        %7Btext: '%5B=%5D foo_bar - baz'%7D%0A      %5D%0A    %7D)%0A    expect(doc.$item(1).valueOf()).to.eq(5 - 2)%0A  %7D)%0A%0A  it('references %60$name%60 correctly', () =%3E %7B%0A    let doc = calculist.new(%7B text: 'foo %5B=%5D $name + 1' %7D)%0A    expect(doc.valueOf()).to.eq('foo1')%0A  %7D)%0A%0A  it('calculates %60sum($items)%60 correctly', () =%3E %7B%0A    let doc = calculist.new(%7B%0A      text: 'foo %5B=%5D sum($items)',%0A      items: %5B%0A        %7Btext: '%5B:%5D 1'%7D,%0A        %7Btext: '%5B:%5D 1'%7D%0A      %5D%0A    %7D)%0A    expect(doc.valueOf()).to.eq(2
 )%0A  

Add calculation tests