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

Replace with std.asciiUpper with supported by required version of jsonnet #2104

Merged
merged 1 commit into from Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions kubeflow/core/tests/util_test.jsonnet
@@ -1,9 +1,5 @@
local util = import "../util.libsonnet";

std.assertEqual(util.upper("True"), "TRUE") &&
std.assertEqual(util.upper("TrUe"), "TRUE") &&
std.assertEqual(util.upper("true"), "TRUE") &&
std.assertEqual(util.upper("TRUE"), "TRUE") &&
std.assertEqual(util.lower("aTruez"), "atruez") &&
std.assertEqual(util.lower("ATrUez"), "atruez") &&
std.assertEqual(util.lower("atruez"), "atruez") &&
Expand All @@ -25,8 +21,6 @@ std.assertEqual(util.toArray("ca, or,fl, mo"), ["ca", "or", "fl", "mo"]) &&
std.assertEqual(std.length(util.toArray(2)), 0) &&
std.assertEqual(std.length(util.toArray("hello world")), 1) &&
std.assertEqual(std.length(util.toArray([1, 2, 3, 4])), 0) &&
std.assertEqual(util.isUpper(std.substr("Hi", 0, 1)), true) &&
std.assertEqual(util.isUpper(std.substr("lo", 0, 1)), false) &&
std.assertEqual(util.sort(["Craydad", "CCall", "crayon"]), ["CCall", "Craydad", "crayon"]) &&
std.assertEqual(
{
Expand Down
22 changes: 1 addition & 21 deletions kubeflow/core/util.libsonnet
Expand Up @@ -3,26 +3,6 @@
local k = import "k.libsonnet",
local util = self,

// Is the character upper case?
isUpper:: function(c) {
local cp = std.codepoint,
local value = if cp(c) >= 65 && cp(c) < 91 then
true
else
false,
result:: value,
}.result,

// TODO(https://github.com/kubeflow/kubeflow/issues/1826): Replace with std.asciiUpper once supported by required version of jsonnet
// Convert a string to upper case.
upper:: function(x) {
local cp(c) = std.codepoint(c),
local upperLetter(c) = if cp(c) >= 97 && cp(c) < 123 then
std.char(cp(c) - 32)
else c,
result:: std.join("", std.map(upperLetter, std.stringChars(x))),
}.result,

// Convert a string to lower case.
lower:: function(x) {
local cp(c) = std.codepoint(c),
Expand All @@ -39,7 +19,7 @@
if std.type(x) == "boolean" then
x
else if std.type(x) == "string" then
$.upper(x) == "TRUE"
std.asciiUpper(x) == "TRUE"
else if std.type(x) == "number" then
x != 0
else
Expand Down
12 changes: 1 addition & 11 deletions kubeflow/openmpi/util.libsonnet
Expand Up @@ -15,24 +15,14 @@
for keyValue in $.toArray(str)
} else {},

// TODO(https://github.com/kubeflow/kubeflow/issues/1826): Replace with std.asciiUpper once supported by required version of jsonnet
// Convert a string to upper case.
upper:: function(x) {
local cp(c) = std.codepoint(c),
local upLetter(c) = if cp(c) >= 97 && cp(c) < 123 then
std.char(cp(c) - 32)
else c,
result:: std.join("", std.map(upLetter, std.stringChars(x))),
}.result,

// Convert non-boolean types like string,number to a boolean.
// This is primarily intended for dealing with parameters that should be booleans.
toBool:: function(x) {
result::
if std.type(x) == "boolean" then
x
else if std.type(x) == "string" then
$.upper(x) == "TRUE"
std.asciiUpper(x) == "TRUE"
else if std.type(x) == "number" then
x != 0
else
Expand Down
12 changes: 1 addition & 11 deletions kubeflow/weaveflux/util.libsonnet
@@ -1,23 +1,13 @@
// Some useful routines.
{
// TODO(https://github.com/kubeflow/kubeflow/issues/1826): Replace with std.asciiUpper once supported by required version of jsonnet
// Convert a string to upper case.
upper:: function(x) {
local cp(c) = std.codepoint(c),
local upLetter(c) = if cp(c) >= 97 && cp(c) < 123 then
std.char(cp(c) - 32)
else c,
result:: std.join("", std.map(upLetter, std.stringChars(x))),
}.result,

// Convert non-boolean types like string,number to a boolean.
// This is primarily intended for dealing with parameters that should be booleans.
toBool:: function(x) {
result::
if std.type(x) == "boolean" then
x
else if std.type(x) == "string" then
$.upper(x) == "TRUE"
std.asciiUpper(x) == "TRUE"
else if std.type(x) == "number" then
x != 0
else
Expand Down
2 changes: 1 addition & 1 deletion testing/workflows/components/workflows.libsonnet
Expand Up @@ -23,7 +23,7 @@
if std.type(x) == "boolean" then
x
else if std.type(x) == "string" then
$.upper(x) == "TRUE"
std.asciiUpper(x) == "TRUE"
else if std.type(x) == "number" then
x != 0
else
Expand Down