Change reconcile error message for 'positive' integer
This time it *should* work for manifest.yml editor.
This commit is contained in:
@@ -175,7 +175,7 @@ public final class ManifestYmlSchema implements YamlSchema {
|
||||
.build();
|
||||
|
||||
YAtomicType t_strictly_pos_integer = f.yatomic("Strictly Positive Integer");
|
||||
t_strictly_pos_integer.parseWith(ManifestYmlValueParsers.integerAtLeast(1));
|
||||
t_strictly_pos_integer.parseWith(ValueParsers.integerAtLeast(1));
|
||||
|
||||
YAtomicType t_pos_integer = f.yatomic("Positive Integer");
|
||||
t_pos_integer.parseWith(ManifestYmlValueParsers.POS_INTEGER);
|
||||
|
||||
@@ -19,10 +19,10 @@ import java.util.concurrent.Callable;
|
||||
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemType;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileException;
|
||||
import org.springframework.ide.vscode.commons.util.Assert;
|
||||
import org.springframework.ide.vscode.commons.util.EnumValueParser;
|
||||
import org.springframework.ide.vscode.commons.util.StringUtil;
|
||||
import org.springframework.ide.vscode.commons.util.ValueParser;
|
||||
import org.springframework.ide.vscode.commons.util.ValueParsers;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YAtomicType;
|
||||
import org.springframework.ide.vscode.commons.yaml.schema.YValueHint;
|
||||
@@ -38,7 +38,7 @@ import com.google.common.collect.Sets;
|
||||
*/
|
||||
public class ManifestYmlValueParsers {
|
||||
|
||||
public static final ValueParser POS_INTEGER = integerRange(0, null);
|
||||
public static final ValueParser POS_INTEGER = ValueParsers.integerRange(0, null);
|
||||
|
||||
public static final ValueParser MEMORY = new ValueParser() {
|
||||
|
||||
@@ -74,31 +74,6 @@ public class ManifestYmlValueParsers {
|
||||
}
|
||||
};
|
||||
|
||||
public static ValueParser integerAtLeast(final Integer lowerBound) {
|
||||
return integerRange(lowerBound, null);
|
||||
}
|
||||
|
||||
public static ValueParser integerRange(final Integer lowerBound, final Integer upperBound) {
|
||||
Assert.isLegal(lowerBound==null || upperBound==null || lowerBound <= upperBound);
|
||||
return new ValueParser() {
|
||||
@Override
|
||||
public Object parse(String str) throws Exception {
|
||||
int value = Integer.parseInt(str);
|
||||
if (lowerBound!=null && value<lowerBound) {
|
||||
if (lowerBound==0) {
|
||||
throw new NumberFormatException("Value must be positive");
|
||||
} else {
|
||||
throw new NumberFormatException("Value must be at least "+lowerBound);
|
||||
}
|
||||
}
|
||||
if (upperBound!=null && value>upperBound) {
|
||||
throw new NumberFormatException("Value must be at most "+upperBound);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static EnumValueParser fromCFValueHints(Callable<Collection<YValueHint>> hintProvider, YAtomicType type, ProblemType problemType) {
|
||||
return new EnumValueParser(type.toString(), true /*CF value parsers are potentially long running*/, YTypeFactory.valuesFromHintProvider(hintProvider)) {
|
||||
@Override
|
||||
|
||||
@@ -144,7 +144,7 @@ public class ManifestYamlEditorTest {
|
||||
"- name: some-other-name\n" +
|
||||
" instances: 0"
|
||||
);
|
||||
editor.assertProblems("-1|Value must be positive");
|
||||
editor.assertProblems("-1|Value must be at least 0");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -224,7 +224,7 @@ public class ManifestYamlEditorTest {
|
||||
" disk_quota: -2048M\n"
|
||||
);
|
||||
editor.assertProblems(
|
||||
"-3|Value must be positive",
|
||||
"-3|Value must be at least 0",
|
||||
"-1024M|Negative value is not allowed",
|
||||
"-2048M|Negative value is not allowed"
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user