package com.redhat.ceylon.compiler.loader;

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

import com.redhat.ceylon.compiler.typechecker.model.Annotation;
import com.redhat.ceylon.compiler.typechecker.model.Value;

public class TestBitAnnotations {

    @Test
    public void testEncode() {
        final Value v = new Value();
        int b = MetamodelGenerator.encodeAnnotations(v, null);
        Assert.assertEquals(0, b);
        v.getAnnotations().add(new Annotation("shared"));
        b = MetamodelGenerator.encodeAnnotations(v, null);
        Assert.assertEquals(1, b);
        v.getAnnotations().add(new Annotation("actual"));
        b = MetamodelGenerator.encodeAnnotations(v, null);
        Assert.assertEquals(3, b);
        v.getAnnotations().add(new Annotation("default"));
        b = MetamodelGenerator.encodeAnnotations(v, null);
        Assert.assertEquals(11, b);
    }

    @Test
    public void testBits() {
        Assert.assertTrue(JsonPackage.hasAnnotationBit(11, "shared"));
        Assert.assertTrue(JsonPackage.hasAnnotationBit(11, "actual"));
        Assert.assertTrue(JsonPackage.hasAnnotationBit(11, "default"));
        Assert.assertFalse(JsonPackage.hasAnnotationBit(11, "late"));
        Assert.assertFalse(JsonPackage.hasAnnotationBit(11, "formal"));
        Assert.assertFalse(JsonPackage.hasAnnotationBit(11, "abstract"));
        Assert.assertFalse(JsonPackage.hasAnnotationBit(11, "final"));
        Assert.assertFalse(JsonPackage.hasAnnotationBit(11, "native"));
        Assert.assertFalse(JsonPackage.hasAnnotationBit(11, "sealed"));
    }

}

@@ -37,16 +37,116 @@
 oader;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0A
 import o
@@ -162,16 +162,16 @@
 Assert;%0A
-
 import o
@@ -470,32 +470,38 @@
 deAnnotations(v,
+ null,
  null);%0A        
@@ -628,32 +628,38 @@
 deAnnotations(v,
+ null,
  null);%0A        
@@ -786,32 +786,38 @@
 deAnnotations(v,
+ null,
  null);%0A        
@@ -949,24 +949,30 @@
 notations(v,
+ null,
  null);%0A    
@@ -1010,16 +1010,1179 @@
 %0A    %7D%0A%0A
+    private Annotation doc(String text) %7B%0A        final Annotation d = new Annotation(%22doc%22);%0A        d.addPositionalArgment(text);%0A        return d;%0A    %7D%0A%0A    @Test%0A    public void testSplitDocs() %7B%0A        final Value v1 = new Value();%0A        final Value v2 = new Value();%0A        v1.getAnnotations().add(doc(%22value 1%22));%0A        v2.getAnnotations().add(doc(%22value 2%22));%0A        final HashMap%3CString, Object%3E m = new HashMap%3C%3E();%0A        final ArrayList%3CString%3E docs = new ArrayList%3C%3E(2);%0A        MetamodelGenerator.encodeAnnotations(v1, m, docs);%0A        Assert.assertNotNull(m.get(MetamodelGenerator.KEY_ANNOTATIONS));%0A        Assert.assertNotNull(%220%22, ((Map%3CString,List%3CString%3E%3E)m.get(MetamodelGenerator.KEY_ANNOTATIONS)).get(%22doc%22).get(0));%0A        MetamodelGenerator.encodeAnnotations(v2, m, docs);%0A        Assert.assertNotNull(m.get(MetamodelGenerator.KEY_ANNOTATIONS));%0A        Assert.assertNotNull(%221%22, ((Map%3CString,List%3CString%3E%3E)m.get(MetamodelGenerator.KEY_ANNOTATIONS)).get(%22doc%22).get(0));%0A        Assert.assertEquals(2, docs.size());%0A        Assert.assertEquals(%22value 1%22, docs.get(0));%0A        Assert.assertEquals(%22value 2%22, docs.get(1));%0A    %7D%0A%0A
     @Tes

test docs in separate array