package com.yahoo.searchdefinition.processing;

import com.yahoo.searchdefinition.RankProfileRegistry;
import com.yahoo.searchdefinition.SearchBuilder;
import com.yahoo.searchdefinition.parser.ParseException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

/**
 * @author bjorncs
 */
public class FastAccessValidatorTest {

    @Rule
    public final ExpectedException exceptionRule = ExpectedException.none();

    @Test
    public void throws_exception_on_incompatible_use_of_fastaccess() throws ParseException {
        SearchBuilder builder = new SearchBuilder(new RankProfileRegistry());
        builder.importString(
                "search test {\n" +
                "    document test { \n" +
                "        field int_attribute type int { \n" +
                "            indexing: attribute \n" +
                "            attribute: fast-access\n" +
                "        }\n" +
                "        field predicate_attribute type predicate {\n" +
                "            indexing: attribute \n" +
                "            attribute: fast-access\n" +
                "        }\n" +
                "        field tensor_attribute type tensor(x[]) {\n" +
                "            indexing: attribute \n" +
                "            attribute: fast-access\n" +
                "        }\n" +
                "    }\n" +
                "}\n");
        exceptionRule.expect(IllegalArgumentException.class);
        exceptionRule.expectMessage(
                "For search 'test': The following attributes have a type that is incompatible " +
                        "with fast-access: predicate_attribute, tensor_attribute. " +
                        "Predicate, tensor and reference attributes are incompatible with fast-access.");
        builder.build();
    }

}

@@ -41,16 +41,61 @@
 ssing;%0A%0A
+import com.yahoo.config.model.test.TestUtil;%0A
 import c
@@ -141,16 +141,16 @@
 gistry;%0A
-
 import c
@@ -722,28 +722,375 @@
     
-%22search test %7B%5Cn%22 +%0A
+TestUtil.joinLines(%0A                        %22search parent %7B%22,%0A                        %22  document parent %7B%22,%0A                        %22    field int_field type int %7B indexing: attribute %7D%22,%0A                        %22  %7D%22,%0A                        %22%7D%22));%0A        builder.importString(%0A                TestUtil.joinLines(%0A                        %22search test %7B%22,%0A        
     
@@ -1118,30 +1118,34 @@
 ment test %7B 
-%5Cn%22 +%0A
+%22,%0A       
             
@@ -1140,32 +1140,33 @@
                 
+ 
 %22        field i
@@ -1189,22 +1189,25 @@
 e int %7B 
-%5Cn%22 +%0A
+%22,%0A      
         
@@ -1206,32 +1206,34 @@
                 
+  
 %22            ind
@@ -1241,38 +1241,43 @@
 xing: attribute 
-%5Cn%22 +%0A
+%22,%0A        
                 
@@ -1303,38 +1303,43 @@
 ute: fast-access
-%5Cn%22 +%0A
+%22,%0A        
                 
@@ -1340,38 +1340,43 @@
       %22        %7D
-%5Cn%22 +%0A
+%22,%0A        
                 
@@ -1426,22 +1426,22 @@
 dicate %7B
-%5Cn%22 +%0A
+%22,%0A   
         
@@ -1440,32 +1440,37 @@
                 
+     
 %22            ind
@@ -1478,38 +1478,43 @@
 xing: attribute 
-%5Cn%22 +%0A
+%22,%0A        
                 
@@ -1540,38 +1540,43 @@
 ute: fast-access
-%5Cn%22 +%0A
+%22,%0A        
                 
@@ -1577,37 +1577,34 @@
       %22        %7D
-%5Cn%22 +
+%22,
 %0A               
@@ -1596,32 +1596,40 @@
                 
+        
 %22        field t
@@ -1662,22 +1662,27 @@
 r(x%5B%5D) %7B
-%5Cn%22 +%0A
+%22,%0A        
         
@@ -1722,22 +1722,27 @@
 tribute 
-%5Cn%22 +%0A
+%22,%0A        
         
@@ -1788,74 +1788,334 @@
 cess
-%5Cn%22 +%0A                %22        %7D%5Cn%22 +%0A                %22    %7D%5Cn%22 +%0A
+%22,%0A                        %22        %7D%22,%0A                        %22        field reference_attribute type reference%3Cparent%3E %7B%22,%0A                        %22            indexing: attribute %22,%0A                        %22            attribute: fast-access%22,%0A                        %22        %7D%22,%0A                        %22    %7D%22,%0A        
     
@@ -2132,11 +2132,10 @@
   %22%7D
-%5Cn
 %22
+)
 );%0A 
@@ -2326,24 +2326,24 @@
 patible %22 +%0A
-
             
@@ -2410,16 +2410,37 @@
 ttribute
+, reference_attribute
 . %22 +%0A  

Use joinLines + add reference field