Expressions { public static boolean isFalsy(@Nullable Expression expression) { if (expression == null) { return false; } switch (expression.getKind()) { case NAME: return "False".equals(((Name) expression).name()); case NONE: return true; case STRING_LITERAL: return unescape((StringLiteral) expression).isEmpty(); case NUMERIC_LITERAL: return ZERO_VALUES.contains(((NumericLiteral) expression).valueAsString()); case LIST_LITERAL: return ((ListLiteral) expression).elements().expressions().isEmpty(); case TUPLE: return ((Tuple) expression).elements().isEmpty(); case DICTIONARY_LITERAL: return ((DictionaryLiteral) expression).elements().isEmpty(); default: return false; } } private  Expressions(); static boolean isFalsy(@Nullable Expression expression); static Expression singleAssignedValue(Name name); static Expression removeParentheses(@Nullable Expression expression); static String unescape(StringLiteral stringLiteral); static String unescape(StringElement stringElement);  }
@Test public void falsy() { assertThat(isFalsy(null)).isFalse(); assertThat(isFalsy(exp("True"))).isFalse(); assertThat(isFalsy(exp("False"))).isTrue(); assertThat(isFalsy(exp("x"))).isFalse(); assertThat(isFalsy(exp("None"))).isTrue(); assertThat(isFalsy(exp("''"))).isTrue(); assertThat(isFalsy(exp("'\\\n'"))).isTrue(); assertThat(isFalsy(exp("'x'"))).isFalse(); assertThat(isFalsy(exp("' '"))).isFalse(); assertThat(isFalsy(exp("''"))).isTrue(); assertThat(isFalsy(exp("\"\""))).isTrue(); assertThat(isFalsy(exp("'' 'x'"))).isFalse(); assertThat(isFalsy(exp("'' ''"))).isTrue(); assertThat(isFalsy(exp("1"))).isFalse(); assertThat(isFalsy(exp("0"))).isTrue(); assertThat(isFalsy(exp("0.0"))).isTrue(); assertThat(isFalsy(exp("0j"))).isTrue(); assertThat(isFalsy(exp("3.14"))).isFalse(); assertThat(isFalsy(exp("[x]"))).isFalse(); assertThat(isFalsy(exp("[]"))).isTrue(); assertThat(isFalsy(exp("(x)"))).isFalse(); assertThat(isFalsy(exp("()"))).isTrue(); assertThat(isFalsy(exp("{x:y}"))).isFalse(); assertThat(isFalsy(exp("{x}"))).isFalse(); assertThat(isFalsy(exp("{}"))).isTrue(); assertThat(isFalsy(exp("x.y"))).isFalse(); }