package ruke.vrj.compiler;

import org.junit.Assert;
import org.junit.Test;

/**
 * Created by Ruke on 18/12/2016.
 */
public class TypeTest {

  @Test
  public void checkAlreadyDefined() {
    String code = String.join("\n",
        "type buff extends integer",
        "type buff extends integer",
        "type bar extends integer"
    );

    Compiler compiler = new Compiler();
    compiler.compile(code);

    Assert.assertEquals(1, compiler.getAllErrors().size());
    Assert.assertEquals(
        "2:5 - Type buff is already defined",
        compiler.getAllErrors().get(0).getMessage()
    );
  }

  @Test
  public void checkDefined() {
    String code = String.join("\n",
        "type lorem extends ipsum"
    );

    Compiler compiler = new Compiler();
    compiler.compile(code);

    Assert.assertEquals(1, compiler.getAllErrors().size());
    Assert.assertEquals(
        "1:19 - ipsum is not defined",
        compiler.getAllErrors().get(0).getMessage()
    );
  }

}

@@ -81,37 +81,1136 @@
 %0A * 
-Created by Ruke on 18/12/2016
+MIT License%0A *%0A * Copyright (c) 2017 Franco Montenegro%0A *%0A * Permission is hereby granted, free of charge, to any person obtaining a copy%0A * of this software and associated documentation files (the %22Software%22), to deal%0A * in the Software without restriction, including without limitation the rights%0A * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell%0A * copies of the Software, and to permit persons to whom the Software is%0A * furnished to do so, subject to the following conditions:%0A *%0A * The above copyright notice and this permission notice shall be included in all%0A * copies or substantial portions of the Software.%0A *%0A * THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR%0A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,%0A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE%0A * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER%0A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,%0A * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE%0A * SOFTWARE
 .%0A *
@@ -1262,27 +1262,14 @@
 oid 
-checkAlreadyD
+d
 efine
-d
 () %7B
@@ -1265,32 +1265,38 @@
  define() %7B%0A    
+final 
 String code = St
@@ -1329,65 +1329,11 @@
 ype 
-buff extends integer%22,%0A        %22type buff extends integer
+foo
 %22,%0A 
@@ -1361,15 +1361,11 @@
 nds 
-integer
+foo
 %22%0A  
@@ -1366,32 +1366,38 @@
 oo%22%0A    );%0A%0A    
+final 
 Compiler compile
@@ -1408,32 +1408,33 @@
 new Compiler();%0A
+%0A
     compiler.com
@@ -1459,34 +1459,29 @@
 ssert.assert
-Equals(1, 
+True(
 compiler.get
@@ -1484,156 +1484,27 @@
 .get
-AllErrors().size());%0A    Assert.assertEquals(%0A        %222:5 - Type buff is already defined%22,%0A        compiler.getAllErrors().get(0).getMessage()%0A    
+Results().isEmpty()
 );%0A 
@@ -1533,13 +1533,15 @@
 oid 
-check
+already
 Defi
@@ -1552,16 +1552,22 @@
 ) %7B%0A    
+final 
 String c
@@ -1608,27 +1608,51 @@
 ype 
-lorem extends ipsum
+foo%22,%0A        %22type foo%22,%0A        %22type bar
 %22%0A  
@@ -1661,16 +1661,22 @@
 );%0A%0A    
+final 
 Compiler
@@ -1703,16 +1703,17 @@
 iler();%0A
+%0A
     comp
@@ -1768,32 +1768,30 @@
 compiler.get
-AllError
+Result
 s().size());
@@ -1829,35 +1829,57 @@
    %22
-1:19 - ipsum is not defined
+(2,5,8): Symbol foo is already defined in (1,5,8)
 %22,%0A 
@@ -1901,16 +1901,14 @@
 .get
-AllError
+Result
 s().
@@ -1918,18 +1918,16 @@
 (0).
-getMessage
+toString
 ()%0A 

Add type compiler tests