Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add test functions for parse #6

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/test/java/com/jsoniter/TestOmitValue.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,63 @@
package com.jsoniter;

import com.jsoniter.spi.OmitValue;
import com.jsoniter.spi.OmitValue.*;
import junit.framework.TestCase;
import java.lang.reflect.Type;


public class TestOmitValue extends TestCase {

// Tests parsing a boolean type with a "true" string as the default value to omit.
// Resulting OmitValue should omit true and not omit false.
public void test_parseBooleanTypeWithTrueString() {
Type valueType = boolean.class;
String defaultValueToOmit = "true";
OmitValue result = Parsed.parse(valueType, defaultValueToOmit);
assertTrue(result.shouldOmit(true));
assertFalse(result.shouldOmit(false));
}

// Tests parsing a Boolean type with a "false" string as the default value to omit.
// Resulting OmitValue should omit false and not omit true.
public void test_parseBooleanTypeWithFalseString() {
Type valueType = Boolean.class;
String defaultValueToOmit = "false";
OmitValue result = Parsed.parse(valueType, defaultValueToOmit);
assertTrue(result.shouldOmit(false));
assertFalse(result.shouldOmit(true));
}

// Tests parsing an integer type with a "0" string as the default value to omit.
// Resulting OmitValue should omit 0 and not omit other integers (e.g., 42).
public void test_parseIntegerTypeWithZeroString() {
Type valueType = int.class;
String defaultValueToOmit = "0";
OmitValue result = Parsed.parse(valueType, defaultValueToOmit);
assertTrue(result.shouldOmit(0));
assertFalse(result.shouldOmit(42));
}

// Tests parsing a float type with a "0.0F" string as the default value to omit.
// Resulting OmitValue should omit 0.0F and not omit other floats (e.g., 3.14F).
public void test_parseFloatTypeWithZeroString() {
Type valueType = float.class;
String defaultValueToOmit = "0.0F";
OmitValue result = Parsed.parse(valueType, defaultValueToOmit);
assertTrue(result.shouldOmit(0.0F));
assertFalse(result.shouldOmit(3.14F));
}

// Tests parsing a double type with a "0.0D" string as the default value to omit.
// Resulting OmitValue should omit 0.0D and not omit other doubles (e.g., 2.718D).
public void test_parseDoubleTypeWithZeroString() {
Type valueType = Double.class;
String defaultValueToOmit = "0.0D";
OmitValue result = Parsed.parse(valueType, defaultValueToOmit);
assertTrue(result.shouldOmit(0.0D));
assertFalse(result.shouldOmit(2.718D));
}

public void test_shouldOmitInputPositiveOutputFalse() {

// Arrange
Expand Down