import cssRuleIsKeyframe from "../cssRuleIsKeyframe"
import postcss from "postcss"
import test from "tape"

test("cssRuleIsKeyframe", t => {
  postcssOkCheck(t, "@keyframes identifier { to {} }", "to")
  postcssOkCheck(t, "@keyframes identifier { from {} }", "from")
  postcssOkCheck(t, "@keyframes identifier { 50% {} }", "percentage")

  postcssNotOkCheck(t, "a {}", "rule")
  postcssNotOkCheck(t, "a { & b {} }", "direct nested rule")
  postcssNotOkCheck(t, "a { @nest b & {} }", "@nest nested rule")
  postcssNotOkCheck(t, "@media print { a {} }", "@media")
  postcssNotOkCheck(t, "@supports (animation-name: test) { a {} }", "@supports")
  postcssNotOkCheck(t, "@document url(http://www.w3.org/) { a {} }", "@document")
  postcssNotOkCheck(t, "@page :pseudo-class { a {} }", "page")
  postcssNotOkCheck(t, "@font-face { src: url(x.woff) }", "font-face")

  t.end()
})

function postcssOkCheck(t, css, desc) {
  postcss().process(css).then(result => {
    result.root.walkRules(rule => {
      t.ok(cssRuleIsKeyframe(rule), desc)
    })
  })
}

function postcssNotOkCheck(t, css, desc) {
  postcss().process(css).then(result => {
    result.root.walkRules(rule => {
      t.notOk(cssRuleIsKeyframe(rule), desc)
    })
  })
}

@@ -134,36 +134,38 @@
  t =%3E %7B%0A
+%0A
   
-postcssOkCheck(t, 
+t.plan(9)%0A%0A  rules(
 %22@keyfra
@@ -195,181 +195,282 @@
 %7D%22, 
-%22to%22)%0A  postcssOkCheck(t, %22@keyframes identifier %7B from %7B%7D %7D%22, %22from%22)%0A  postcssOkCheck(t, %22@keyframes identifier %7B 50%25 %7B%7D %7D%22, %22percentage%22)%0A%0A  postcssNotOkCheck(t, 
+rule =%3E %7B%0A    t.ok(cssRuleIsKeyframe(rule), %22to%22)%0A  %7D)%0A  rules(%22@keyframes identifier %7B from %7B%7D %7D%22, rule =%3E %7B%0A    t.ok(cssRuleIsKeyframe(rule), %22from%22)%0A  %7D)%0A  rules(%22@keyframes identifier %7B 50%25 %7B%7D %7D%22, rule =%3E %7B%0A    t.ok(cssRuleIsKeyframe(rule), %2250%25%22)%0A  %7D)%0A%0A  rules(
 %22a %7B%7D%22, 
 %22rul
@@ -469,56 +469,149 @@
 %7D%22, 
-%22
 rule
-%22)%0A  postcssNotOkCheck(t, %22a %7B & b %7B%7D %7D%22, %22
+ =%3E %7B%0A    t.notOk(cssRuleIsKeyframe(rule), %22rule%22)%0A  %7D)%0A  rules(%22a %7B & b %7B%7D %7D%22, rule =%3E %7B%0A    t.notOk(cssRuleIsKeyframe(rule), %22rule and 
 dire
@@ -629,37 +629,27 @@
 ule%22)%0A  
-postcssNotOkCheck(t, 
+%7D)%0A  rules(
 %22a %7B @ne
@@ -666,507 +666,229 @@
 %7D%22, 
-%22@nest nested rule%22)%0A  postcssNotOkCheck(t, %22@media print %7B a %7B%7D %7D%22, %22@media%22)%0A  postcssNotOkCheck(t, %22@supports (animation-name: test) %7B a %7B%7D %7D%22, %22@supports%22)%0A  postcssNotOkCheck(t, %22@document url(http://www.w3.org/) %7B a %7B%7D %7D%22, %22@document%22)%0A  postcssNotOkCheck(t, %22@page :pseudo-class %7B a %7B%7D %7D%22, %22page%22)%0A  postcssNotOkCheck(t, %22@font-face %7B src: url(x.woff) %7D%22, %22font-face
+rule =%3E %7B%0A    t.notOk(cssRuleIsKeyframe(rule), %22@nest nested rule%22)%0A  %7D)%0A  rules(%22@media print %7B a %7B%7D %7D%22, rule =%3E %7B%0A    t.notOk(cssRuleIsKeyframe(rule), %22@media
 %22)%0A
-%0A
   
-t.end()%0A%7D)%0A%0Afunction postcssOkCheck(t, css, desc) %7B%0A  postcss().process(css).then(result =%3E %7B%0A    result.root.walkRules(
+%7D)%0A  rules(%22@supports (animation-name: test) %7B a %7B%7D %7D%22, 
 rule
@@ -897,21 +897,22 @@
 %3E %7B%0A    
-  t.o
+t.notO
 k(cssRul
@@ -930,35 +930,36 @@
 (rule), 
-desc
+%22@supports%22
 )%0A
-  
   %7D)%0A
-  
 %7D)
-%0A%7D
 %0A%0Afuncti
@@ -965,38 +965,21 @@
 ion 
-postcssNotOkCheck(t, 
+rules(
 css, 
-des
 c
+b
 ) %7B%0A
@@ -1050,68 +1050,10 @@
 les(
-rule =%3E %7B%0A      t.notOk(cssRuleIsKeyframe(rule), desc)%0A    %7D
+cb
 )%0A  

Restructure tests