mirror of
				https://github.com/art-ist/mustache-sharp.git
				synced 2024-06-16 21:05:32 +00:00 
			
		
		
		
	Treat DBNull as False in Conditions
This commit is contained in:
		
							parent
							
								
									2bf2f0c25c
								
							
						
					
					
						commit
						76a3f60a94
					
				| @ -792,6 +792,110 @@ Middle"; | ||||
|             Assert.AreEqual("BeforeAfter", result, "The wrong text was generated."); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// If the condition evaluates to false, the content of an if statement should not be printed. | ||||
|         /// </summary> | ||||
|         [TestMethod] | ||||
|         public void TestCompile_If_null_SkipsContent() | ||||
|         { | ||||
|             FormatCompiler parser = new FormatCompiler(); | ||||
|             const string format = "Before{{#if this}}Content{{/if}}After"; | ||||
|             Generator generator = parser.Compile(format); | ||||
|             string result = generator.Render(null); | ||||
|             Assert.AreEqual("BeforeAfter", result, "The wrong text was generated."); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// If the condition evaluates to false, the content of an if statement should not be printed. | ||||
|         /// </summary> | ||||
|         [TestMethod] | ||||
|         public void TestCompile_If_DBNull_SkipsContent() | ||||
|         { | ||||
|             FormatCompiler parser = new FormatCompiler(); | ||||
|             const string format = "Before{{#if this}}Content{{/if}}After"; | ||||
|             Generator generator = parser.Compile(format); | ||||
|             string result = generator.Render(DBNull.Value); | ||||
|             Assert.AreEqual("BeforeAfter", result, "The wrong text was generated."); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// If the condition evaluates to false, the content of an if statement should not be printed. | ||||
|         /// </summary> | ||||
|         [TestMethod] | ||||
|         public void TestCompile_If_EmptyIEnumerable_SkipsContent() | ||||
|         { | ||||
|             FormatCompiler parser = new FormatCompiler(); | ||||
|             const string format = "Before{{#if this}}Content{{/if}}After"; | ||||
|             Generator generator = parser.Compile(format); | ||||
|             string result = generator.Render(Enumerable.Empty<int>()); | ||||
|             Assert.AreEqual("BeforeAfter", result, "The wrong text was generated."); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// If the condition evaluates to false, the content of an if statement should not be printed. | ||||
|         /// </summary> | ||||
|         [TestMethod] | ||||
|         public void TestCompile_If_NullChar_SkipsContent() | ||||
|         { | ||||
|             FormatCompiler parser = new FormatCompiler(); | ||||
|             const string format = "Before{{#if this}}Content{{/if}}After"; | ||||
|             Generator generator = parser.Compile(format); | ||||
|             string result = generator.Render('\0'); | ||||
|             Assert.AreEqual("BeforeAfter", result, "The wrong text was generated."); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// If the condition evaluates to false, the content of an if statement should not be printed. | ||||
|         /// </summary> | ||||
|         [TestMethod] | ||||
|         public void TestCompile_If_ZeroInt_SkipsContent() | ||||
|         { | ||||
|             FormatCompiler parser = new FormatCompiler(); | ||||
|             const string format = "Before{{#if this}}Content{{/if}}After"; | ||||
|             Generator generator = parser.Compile(format); | ||||
|             string result = generator.Render(0); | ||||
|             Assert.AreEqual("BeforeAfter", result, "The wrong text was generated."); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// If the condition evaluates to false, the content of an if statement should not be printed. | ||||
|         /// </summary> | ||||
|         [TestMethod] | ||||
|         public void TestCompile_If_ZeroFloat_SkipsContent() | ||||
|         { | ||||
|             FormatCompiler parser = new FormatCompiler(); | ||||
|             const string format = "Before{{#if this}}Content{{/if}}After"; | ||||
|             Generator generator = parser.Compile(format); | ||||
|             string result = generator.Render(0f); | ||||
|             Assert.AreEqual("BeforeAfter", result, "The wrong text was generated."); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// If the condition evaluates to false, the content of an if statement should not be printed. | ||||
|         /// </summary> | ||||
|         [TestMethod] | ||||
|         public void TestCompile_If_ZeroDouble_SkipsContent() | ||||
|         { | ||||
|             FormatCompiler parser = new FormatCompiler(); | ||||
|             const string format = "Before{{#if this}}Content{{/if}}After"; | ||||
|             Generator generator = parser.Compile(format); | ||||
|             string result = generator.Render(0.0); | ||||
|             Assert.AreEqual("BeforeAfter", result, "The wrong text was generated."); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// If the condition evaluates to false, the content of an if statement should not be printed. | ||||
|         /// </summary> | ||||
|         [TestMethod] | ||||
|         public void TestCompile_If_ZeroDecimal_SkipsContent() | ||||
|         { | ||||
|             FormatCompiler parser = new FormatCompiler(); | ||||
|             const string format = "Before{{#if this}}Content{{/if}}After"; | ||||
|             Generator generator = parser.Compile(format); | ||||
|             string result = generator.Render(0m); | ||||
|             Assert.AreEqual("BeforeAfter", result, "The wrong text was generated."); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// If the condition evaluates to false, the content of an if statement should not be printed. | ||||
|         /// </summary> | ||||
| @ -920,7 +1024,7 @@ Content{{/if}}"; | ||||
|         /// If the a header follows a footer, it shouldn't generate a new line. | ||||
|         /// </summary> | ||||
|         [TestMethod] | ||||
|         public void TestCompile_IfNewLineContentNewLineEndIfIfNewLineContenNewLineEndIf_PrintsContent() | ||||
|         public void TestCompile_IfNewLineContentNewLineEndIfIfNewLineContentNewLineEndIf_PrintsContent() | ||||
|         { | ||||
|             FormatCompiler parser = new FormatCompiler(); | ||||
|             const string format = @"{{#if this}}
 | ||||
|  | ||||
| @ -65,7 +65,7 @@ namespace Mustache | ||||
| 
 | ||||
|         private bool isConditionSatisfied(object condition) | ||||
|         { | ||||
|             if (condition == null) | ||||
|             if (condition == null || condition == DBNull.Value) | ||||
|             { | ||||
|                 return false; | ||||
|             } | ||||
|  | ||||
| @ -14,6 +14,6 @@ using System.Runtime.InteropServices; | ||||
| [assembly: CLSCompliant(true)] | ||||
| [assembly: ComVisible(false)] | ||||
| [assembly: Guid("e5a4263d-d450-4d85-a4d5-44c0a2822668")] | ||||
| [assembly: AssemblyVersion("0.2.8.0")] | ||||
| [assembly: AssemblyFileVersion("0.2.8.0")] | ||||
| [assembly: AssemblyVersion("0.2.8.1")] | ||||
| [assembly: AssemblyFileVersion("0.2.8.1")] | ||||
| [assembly: InternalsVisibleTo("mustache-sharp.test")] | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Travis Parks
						Travis Parks