diff --git a/tests/rules-data/select/psykoty.xml b/tests/rules-data/select/psykoty.xml
new file mode 100644
index 0000000000000000000000000000000000000000..c529b34911c7b1ad3a3f5deb8622f3ae96e9e6c7
--- /dev/null
+++ b/tests/rules-data/select/psykoty.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE cesAna SYSTEM "xcesAnaIPI.dtd">
+<cesAna xmlns:xlink="http://www.w3.org/1999/xlink" version="1.0" type="lex disamb">
+<chunkList>
+ <chunk>
+  <chunk type="s">
+   <tok>
+    <orth>Duże</orth>
+    <lex><base>duży</base><ctag>adj:pl:acc:f:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:acc:m2:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:acc:m3:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:acc:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:nom:f:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:nom:m2:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:nom:m3:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:nom:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:voc:f:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:voc:m2:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:voc:m3:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:voc:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:sg:acc:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:sg:nom:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:sg:voc:n:pos</ctag></lex>
+   </tok>
+   <tok>
+    <orth>psy</orth>
+    <lex><base>pies</base><ctag>subst:pl:acc:m2</ctag></lex>
+    <lex><base>pies</base><ctag>subst:pl:nom:m2</ctag></lex>
+    <lex><base>pies</base><ctag>subst:pl:voc:m2</ctag></lex>
+   </tok>
+   <tok>
+    <orth>i</orth>
+    <lex><base>i</base><ctag>conj</ctag></lex>
+   </tok>
+   <tok>
+    <orth>koty</orth>
+    <lex><base>kot</base><ctag>subst:pl:acc:m2</ctag></lex>
+    <lex><base>kot</base><ctag>subst:pl:nom:m1</ctag></lex>
+    <lex><base>kot</base><ctag>subst:pl:nom:m2</ctag></lex>
+    <lex><base>kot</base><ctag>subst:pl:voc:m1</ctag></lex>
+    <lex><base>kot</base><ctag>subst:pl:voc:m2</ctag></lex>
+    <lex><base>kota</base><ctag>subst:pl:acc:f</ctag></lex>
+    <lex><base>kota</base><ctag>subst:pl:nom:f</ctag></lex>
+    <lex><base>kota</base><ctag>subst:pl:voc:f</ctag></lex>
+    <lex><base>kota</base><ctag>subst:sg:gen:f</ctag></lex>
+    <lex><base>koty</base><ctag>subst:pl:acc:n</ctag></lex>
+    <lex><base>koty</base><ctag>subst:pl:nom:n</ctag></lex>
+    <lex><base>koty</base><ctag>subst:pl:voc:n</ctag></lex>
+   </tok>
+  </chunk>
+ </chunk>
+</chunkList>
+</cesAna>
diff --git a/tests/rules-data/select/sel_agr.ccl b/tests/rules-data/select/sel_agr.ccl
new file mode 100644
index 0000000000000000000000000000000000000000..6f8fc99bab98ecf9f988e57c9e481097d9c052fc
--- /dev/null
+++ b/tests/rules-data/select/sel_agr.ccl
@@ -0,0 +1,23 @@
+rules(
+	rule("sel-agr0",
+		and(
+			equal(class[0], subst),
+			equal(class[2], subst),
+			in(base[1], ["i", "lub"])
+		),
+		select(
+			agrpp(0,2,{nmb,gnd,cas})
+		)
+	),
+	rule("sel-agr2",
+		and(
+			equal(class[0], subst),
+			equal(class[-2], subst),
+			in(base[-1], ["i", "lub"])
+		),
+		select(
+			agrpp(-2,0,{nmb,gnd,cas})
+		)
+	)
+)
+
diff --git a/tests/rules-data/select/sel_agr.out.xml b/tests/rules-data/select/sel_agr.out.xml
new file mode 100644
index 0000000000000000000000000000000000000000..461c67a2d551024f1c8d4f7f2a73e7a9b09966b3
--- /dev/null
+++ b/tests/rules-data/select/sel_agr.out.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE cesAna SYSTEM "xcesAnaIPI.dtd">
+<cesAna xmlns:xlink="http://www.w3.org/1999/xlink" version="1.0" type="lex disamb">
+<chunkList>
+ <chunk>
+  <chunk type="s">
+   <tok>
+    <orth>Duże</orth>
+    <lex><base>duży</base><ctag>adj:pl:acc:f:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:acc:m2:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:acc:m3:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:acc:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:nom:f:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:nom:m2:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:nom:m3:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:nom:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:voc:f:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:voc:m2:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:voc:m3:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:voc:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:sg:acc:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:sg:nom:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:sg:voc:n:pos</ctag></lex>
+   </tok>
+   <tok>
+    <orth>psy</orth>
+    <lex><base>pies</base><ctag>subst:pl:acc:m2</ctag></lex>
+    <lex><base>pies</base><ctag>subst:pl:nom:m2</ctag></lex>
+    <lex><base>pies</base><ctag>subst:pl:voc:m2</ctag></lex>
+   </tok>
+   <tok>
+    <orth>i</orth>
+    <lex><base>i</base><ctag>conj</ctag></lex>
+   </tok>
+   <tok>
+    <orth>koty</orth>
+    <lex><base>kot</base><ctag>subst:pl:acc:m2</ctag></lex>
+    <lex><base>kot</base><ctag>subst:pl:nom:m2</ctag></lex>
+    <lex><base>kot</base><ctag>subst:pl:voc:m2</ctag></lex>
+  </tok>
+  </chunk>
+ </chunk>
+</chunkList>
+</cesAna>
diff --git a/tests/rules-data/select/seln.ccl b/tests/rules-data/select/seln.ccl
new file mode 100644
index 0000000000000000000000000000000000000000..8cafdf86db0153df1a49bc7c062eb988f30a27e3
--- /dev/null
+++ b/tests/rules-data/select/seln.ccl
@@ -0,0 +1,7 @@
+rules(
+	rule("sel-n",
+		select(
+			equal(gnd[0], {n})
+		)
+	)
+)
diff --git a/tests/rules-data/select/seln.out.xml b/tests/rules-data/select/seln.out.xml
new file mode 100644
index 0000000000000000000000000000000000000000..12407dc6cf8fb1c0bcd45e780d5c54ec9a4dd1de
--- /dev/null
+++ b/tests/rules-data/select/seln.out.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE cesAna SYSTEM "xcesAnaIPI.dtd">
+<cesAna xmlns:xlink="http://www.w3.org/1999/xlink" version="1.0" type="lex disamb">
+<chunkList>
+ <chunk>
+  <chunk type="s">
+   <tok>
+    <orth>Duże</orth>
+    <lex><base>duży</base><ctag>adj:pl:acc:n:pos</ctag></lex>
+   <lex><base>duży</base><ctag>adj:pl:nom:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:voc:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:sg:acc:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:sg:nom:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:sg:voc:n:pos</ctag></lex>
+   </tok>
+   <tok>
+    <orth>psy</orth>
+    <lex><base>pies</base><ctag>subst:pl:acc:m2</ctag></lex>
+    <lex><base>pies</base><ctag>subst:pl:nom:m2</ctag></lex>
+    <lex><base>pies</base><ctag>subst:pl:voc:m2</ctag></lex>
+   </tok>
+   <tok>
+    <orth>i</orth>
+    <lex><base>i</base><ctag>conj</ctag></lex>
+   </tok>
+   <tok>
+    <orth>koty</orth>
+    <lex><base>koty</base><ctag>subst:pl:acc:n</ctag></lex>
+    <lex><base>koty</base><ctag>subst:pl:nom:n</ctag></lex>
+    <lex><base>koty</base><ctag>subst:pl:voc:n</ctag></lex>
+   </tok>
+  </chunk>
+ </chunk>
+</chunkList>
+</cesAna>
diff --git a/tests/rules-data/select/seln1.ccl b/tests/rules-data/select/seln1.ccl
new file mode 100644
index 0000000000000000000000000000000000000000..e8ccbf954b69c000f8efde82cbff4edd507a3cd4
--- /dev/null
+++ b/tests/rules-data/select/seln1.ccl
@@ -0,0 +1,9 @@
+rules(
+	rule("sel-n",
+		and(equal(base[0], "i")),
+		select(
+			1,
+			equal(gnd[1], {n})
+		)
+	)
+)
diff --git a/tests/rules-data/select/seln1.out.xml b/tests/rules-data/select/seln1.out.xml
new file mode 100644
index 0000000000000000000000000000000000000000..6a2e02b327dedfdced099889be97aed21827c5d3
--- /dev/null
+++ b/tests/rules-data/select/seln1.out.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE cesAna SYSTEM "xcesAnaIPI.dtd">
+<cesAna xmlns:xlink="http://www.w3.org/1999/xlink" version="1.0" type="lex disamb">
+<chunkList>
+ <chunk>
+  <chunk type="s">
+   <tok>
+    <orth>Duże</orth>
+    <lex><base>duży</base><ctag>adj:pl:acc:f:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:acc:m2:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:acc:m3:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:acc:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:nom:f:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:nom:m2:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:nom:m3:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:nom:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:voc:f:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:voc:m2:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:voc:m3:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:pl:voc:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:sg:acc:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:sg:nom:n:pos</ctag></lex>
+    <lex><base>duży</base><ctag>adj:sg:voc:n:pos</ctag></lex>
+   </tok>
+   <tok>
+    <orth>psy</orth>
+    <lex><base>pies</base><ctag>subst:pl:acc:m2</ctag></lex>
+    <lex><base>pies</base><ctag>subst:pl:nom:m2</ctag></lex>
+    <lex><base>pies</base><ctag>subst:pl:voc:m2</ctag></lex>
+   </tok>
+   <tok>
+    <orth>i</orth>
+    <lex><base>i</base><ctag>conj</ctag></lex>
+   </tok>
+   <tok>
+    <orth>koty</orth>
+    <lex><base>koty</base><ctag>subst:pl:acc:n</ctag></lex>
+    <lex><base>koty</base><ctag>subst:pl:nom:n</ctag></lex>
+    <lex><base>koty</base><ctag>subst:pl:voc:n</ctag></lex>
+   </tok>
+  </chunk>
+ </chunk>
+</chunkList>
+</cesAna>
diff --git a/tests/rules-data/zero/rule-bad.ccl b/tests/rules-data/zero/rule-bad.ccl
deleted file mode 100644
index d9689adeecdde695a41c3b366f1544147cd6552e..0000000000000000000000000000000000000000
--- a/tests/rules-data/zero/rule-bad.ccl
+++ /dev/null
@@ -1,8 +0,0 @@
-rules(
-	rule("rule1",
-	in(class[0], {conj, qub}),
-	delete(
-		equal(class[0], {qub})
-	)
-	)
-)
diff --git a/tests/rules-data/zero/rule-bad.out.xml b/tests/rules-data/zero/rule-bad.out.xml
deleted file mode 100644
index 3c7bc4f2c2e81dccc8167dea765a1094a2448597..0000000000000000000000000000000000000000
--- a/tests/rules-data/zero/rule-bad.out.xml
+++ /dev/null
@@ -1,168 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE cesAna SYSTEM "xcesAnaIPI.dtd">
-<cesAna version="1.0" type="lex disamb">
-<chunkList>
-<chunk id="ch51" type="tok">
-<chunk type="s">
-<tok>
-<orth>Uważam</orth>
-<lex disamb="1"><base>uważać</base><ctag>fin:sg:pri:imperf</ctag></lex>
-</tok>
-<ns/>
-<tok>
-<orth>,</orth>
-<lex disamb="1"><base>,</base><ctag>interp</ctag></lex>
-</tok>
-<tok>
-<orth>że</orth>
-<lex disamb="1"><base>że</base><ctag>conj</ctag></lex>
-</tok>
-<tok>
-<orth>światopogląd</orth>
-<lex><base>światopogląd</base><ctag>subst:sg:acc:m3</ctag></lex>
-<lex disamb="1"><base>światopogląd</base><ctag>subst:sg:nom:m3</ctag></lex>
-</tok>
-<tok>
-<orth>może</orth>
-<lex><base>może</base><ctag>qub</ctag></lex>
-<lex disamb="1"><base>móc</base><ctag>fin:sg:ter:imperf</ctag></lex>
-</tok>
-<tok>
-<orth>być</orth>
-<lex disamb="1"><base>być</base><ctag>inf:imperf</ctag></lex>
-</tok>
-<tok>
-<orth>materialistyczny</orth>
-<lex><base>materialistyczny</base><ctag>adj:sg:acc:m3:pos</ctag></lex>
-<lex><base>materialistyczny</base><ctag>adj:sg:nom:m1:pos</ctag></lex>
-<lex><base>materialistyczny</base><ctag>adj:sg:nom:m2:pos</ctag></lex>
-<lex disamb="1"><base>materialistyczny</base><ctag>adj:sg:nom:m3:pos</ctag></lex>
-</tok>
-<tok>
-<orth>lub</orth>
-<lex disamb="1"><base>lub</base><ctag>conj</ctag></lex>
-<lex><base>lubić</base><ctag>impt:sg:sec:imperf</ctag></lex>
-</tok>
-<tok>
-<orth>idealistyczny</orth>
-<lex><base>idealistyczny</base><ctag>adj:sg:acc:m3:pos</ctag></lex>
-<lex><base>idealistyczny</base><ctag>adj:sg:nom:m1:pos</ctag></lex>
-<lex><base>idealistyczny</base><ctag>adj:sg:nom:m2:pos</ctag></lex>
-<lex disamb="1"><base>idealistyczny</base><ctag>adj:sg:nom:m3:pos</ctag></lex>
-</tok>
-<tok>
-<orth>(</orth>
-<lex disamb="1"><base>(</base><ctag>interp</ctag></lex>
-</tok>
-<ns/>
-<tok>
-<orth>w</orth>
-<lex><base>w</base><ctag>prep:acc:nwok</ctag></lex>
-<lex disamb="1"><base>w</base><ctag>prep:loc:nwok</ctag></lex>
-</tok>
-<tok>
-<orth>prymitywnych</orth>
-<lex><base>prymitywny</base><ctag>adj:pl:acc:m1:pos</ctag></lex>
-<lex><base>prymitywny</base><ctag>adj:pl:gen:f:pos</ctag></lex>
-<lex><base>prymitywny</base><ctag>adj:pl:gen:m1:pos</ctag></lex>
-<lex><base>prymitywny</base><ctag>adj:pl:gen:m2:pos</ctag></lex>
-<lex><base>prymitywny</base><ctag>adj:pl:gen:m3:pos</ctag></lex>
-<lex><base>prymitywny</base><ctag>adj:pl:gen:n:pos</ctag></lex>
-<lex disamb="1"><base>prymitywny</base><ctag>adj:pl:loc:f:pos</ctag></lex>
-<lex><base>prymitywny</base><ctag>adj:pl:loc:m1:pos</ctag></lex>
-<lex><base>prymitywny</base><ctag>adj:pl:loc:m2:pos</ctag></lex>
-<lex><base>prymitywny</base><ctag>adj:pl:loc:m3:pos</ctag></lex>
-<lex><base>prymitywny</base><ctag>adj:pl:loc:n:pos</ctag></lex>
-</tok>
-<tok>
-<orth>cywilizacjach</orth>
-<lex disamb="1"><base>cywilizacja</base><ctag>subst:pl:loc:f</ctag></lex>
-</tok>
-<tok>
-<orth>nawet</orth>
-<lex disamb="1"><base>nawet</base><ctag>qub</ctag></lex>
-</tok>
-<tok>
-<orth>magiczny</orth>
-<lex><base>magiczny</base><ctag>adj:sg:acc:m3:pos</ctag></lex>
-<lex><base>magiczny</base><ctag>adj:sg:nom:m1:pos</ctag></lex>
-<lex><base>magiczny</base><ctag>adj:sg:nom:m2:pos</ctag></lex>
-<lex disamb="1"><base>magiczny</base><ctag>adj:sg:nom:m3:pos</ctag></lex>
-</tok>
-<ns/>
-<tok>
-<orth>)</orth>
-<lex disamb="1"><base>)</base><ctag>interp</ctag></lex>
-</tok>
-<ns/>
-<tok>
-<orth>,</orth>
-<lex disamb="1"><base>,</base><ctag>interp</ctag></lex>
-</tok>
-<tok>
-<orth>ale</orth>
-<lex disamb="1"><base>ale</base><ctag>conj</ctag></lex>
-</tok>
-<tok>
-<orth>nie</orth>
-<lex disamb="1"><base>nie</base><ctag>qub</ctag></lex>
-<lex><base>on</base><ctag>ppron3:pl:acc:f:ter:praep</ctag></lex>
-<lex><base>on</base><ctag>ppron3:pl:acc:m2:ter:praep</ctag></lex>
-<lex><base>on</base><ctag>ppron3:pl:acc:m3:ter:praep</ctag></lex>
-<lex><base>on</base><ctag>ppron3:pl:acc:n:ter:praep</ctag></lex>
-<lex><base>on</base><ctag>ppron3:sg:acc:n:ter:praep</ctag></lex>
-</tok>
-<tok>
-<orth>morski</orth>
-<lex><base>morski</base><ctag>adj:sg:acc:m3:pos</ctag></lex>
-<lex><base>morski</base><ctag>adj:sg:nom:m1:pos</ctag></lex>
-<lex><base>morski</base><ctag>adj:sg:nom:m2:pos</ctag></lex>
-<lex disamb="1"><base>morski</base><ctag>adj:sg:nom:m3:pos</ctag></lex>
-</tok>
-<ns/>
-<tok>
-<orth>,</orth>
-<lex disamb="1"><base>,</base><ctag>interp</ctag></lex>
-</tok>
-<tok>
-<orth>lotniczy</orth>
-<lex><base>lotniczy</base><ctag>adj:pl:nom:m1:pos</ctag></lex>
-<lex><base>lotniczy</base><ctag>adj:sg:acc:m3:pos</ctag></lex>
-<lex><base>lotniczy</base><ctag>adj:sg:nom:m1:pos</ctag></lex>
-<lex><base>lotniczy</base><ctag>adj:sg:nom:m2:pos</ctag></lex>
-<lex disamb="1"><base>lotniczy</base><ctag>adj:sg:nom:m3:pos</ctag></lex>
-</tok>
-<ns/>
-<tok>
-<orth>,</orth>
-<lex disamb="1"><base>,</base><ctag>interp</ctag></lex>
-</tok>
-<tok>
-<orth>rolny</orth>
-<lex><base>rolny</base><ctag>adj:sg:acc:m3:pos</ctag></lex>
-<lex><base>rolny</base><ctag>adj:sg:nom:m1:pos</ctag></lex>
-<lex><base>rolny</base><ctag>adj:sg:nom:m2:pos</ctag></lex>
-<lex disamb="1"><base>rolny</base><ctag>adj:sg:nom:m3:pos</ctag></lex>
-</tok>
-<tok>
-<orth>czy</orth>
-<lex disamb="1"><base>czy</base><ctag>conj</ctag></lex>
-<lex><base>czy</base><ctag>qub</ctag></lex>
-</tok>
-<tok>
-<orth>leśny</orth>
-<lex><base>leśny</base><ctag>adj:sg:acc:m3:pos</ctag></lex>
-<lex><base>leśny</base><ctag>adj:sg:nom:m1:pos</ctag></lex>
-<lex><base>leśny</base><ctag>adj:sg:nom:m2:pos</ctag></lex>
-<lex disamb="1"><base>leśny</base><ctag>adj:sg:nom:m3:pos</ctag></lex>
-</tok>
-<ns/>
-<tok>
-<orth>.</orth>
-<lex disamb="1"><base>.</base><ctag>interp</ctag></lex>
-</tok>
-</chunk>
-</chunk>
-</chunkList>
-</cesAna>
-