コード例 #1
0
ファイル: StyleAPITest.cs プロジェクト: ajayumi/Jumony
    public void SetClassTest()
    {
      var element = new JumonyParser().Parse( "<div></div>" ).Elements().First();

      element.Class( "test" );
      Assert.AreEqual( element.Attribute( "class" ).Value(), "test", ".Class( name ) 测试不通过" );

      element.Class( "-test" );
      Assert.AreEqual( element.Attribute( "class" ).Value() ?? "", "", ".Class( -name ) 测试不通过" );

      element.Class( "~test" );
      Assert.AreEqual( element.Attribute( "class" ).Value(), "test", ".Class( ~name ) 测试不通过" );

      element.Class( "~test" );
      Assert.AreEqual( element.Attribute( "class" ).Value() ?? "", "", ".Class( ~name ) 测试不通过" );

      element.Class( "~test" );
      Assert.AreEqual( element.Attribute( "class" ).Value(), "test", ".Class( ~name ) 测试不通过" );

      element.Class().Toggle( "test" );
      Assert.AreEqual( element.Attribute( "class" ).Value() ?? "", "", ".Class().Toggle( name ) 测试不通过" );

      element.Class().Toggle( "test" );
      Assert.AreEqual( element.Attribute( "class" ).Value(), "test", ".Class().Toggle( name ) 测试不通过" );

      element.Class().Toggle( "test" );
      Assert.AreEqual( element.Attribute( "class" ).Value() ?? "", "", ".Class().Toggle( name ) 测试不通过" );

      element.Class( "+deleted", "+completed" );//class="deleted completed"
      Assert.IsTrue( CssParser.Create( element.Document, ".deleted.completed" ).IsEligible( element ), ".Class( +name, +name )" );

      element.Class( "+deleted", "~completed" );//class="deleted"
      Assert.IsFalse( CssParser.Create( element.Document, ".deleted.completed" ).IsEligible( element ), ".Class( +name, ~name )" );
      Assert.IsTrue( CssParser.Create( element.Document, ".deleted" ).IsEligible( element ), ".Class( +name, ~name )" );

      element.Class( "~deleted", "~completed" );//class="completed"
      Assert.IsFalse( CssParser.Create( element.Document, ".deleted.completed" ).IsEligible( element ), ".Class( ~name, ~name )" );
      Assert.IsTrue( CssParser.Create( element.Document, ".completed" ).IsEligible( element ), ".Class( ~name, ~name )" );

      element.Class( "~deleted ~completed" );//class="deleted"
      Assert.IsFalse( CssParser.Create( element.Document, ".deleted.completed" ).IsEligible( element ), ".Class( ~name ~name )" );
      Assert.IsTrue( CssParser.Create( element.Document, ".deleted" ).IsEligible( element ), ".Class( ~name ~name )" );

      element.Class( "deleted completed" );//class="deleted completed"
      Assert.IsTrue( CssParser.Create( element.Document, ".deleted.completed" ).IsEligible( element ), ".Class( name name )" );

      element.Class( "+deleted ~completed" );//class="deleted"
      Assert.IsFalse( CssParser.Create( element.Document, ".deleted.completed" ).IsEligible( element ), ".Class( +name, ~name )" );
      Assert.IsTrue( CssParser.Create( element.Document, ".deleted" ).IsEligible( element ), ".Class( +name, ~name )" );

    }