mirror of
https://github.com/tweag/nickel.git
synced 2024-09-19 23:47:54 +03:00
Fix tests: use new comma syntax in examples
This commit is contained in:
parent
9023e84473
commit
c95d14b88a
@ -1,4 +1,3 @@
|
||||
let strings = { length = fun x => 1; substring = fun start end s => "W"} in
|
||||
// Validate and normalize gcc flags. They can be either a string `-Wextra` or
|
||||
// a structured value `{flag = "W", arg = "extra"}`. Arguments are not checked.
|
||||
let GccFlag =
|
||||
@ -6,8 +5,8 @@ let GccFlag =
|
||||
let available = ["W", "c", "S", "e", "o"] in
|
||||
fun label value =>
|
||||
if builtins.isStr value then
|
||||
if strings.length value > 0 && lists.any (fun x => x == strings.substring 0
|
||||
1 value) available then
|
||||
if strings.length value > 0 &&
|
||||
lists.any (fun x => x == strings.substring value 0 1) available then
|
||||
value
|
||||
else
|
||||
contracts.blame (contracts.tag "unknown flag #{value}" label)
|
||||
@ -20,7 +19,7 @@ let GccFlag =
|
||||
contracts.blame (contracts.tag "unkown flag #{value.flag}")
|
||||
else
|
||||
contracts.blame (contracts.tag "bad record structure: missing field
|
||||
`flag` org `arg`" label)
|
||||
`flag` or `arg`" label)
|
||||
else
|
||||
contracts.blame (contracts.tag "expected record or string") in
|
||||
|
||||
@ -44,14 +43,14 @@ let Contract = {
|
||||
pathLibC | doc "Path to libc."
|
||||
| #Path
|
||||
| #SharedObjectFile
|
||||
| default = "/lib/x86_64-linux-gnu/libc.so";
|
||||
| default = "/lib/x86_64-linux-gnu/libc.so",
|
||||
|
||||
flags | doc "
|
||||
Additional flags to pass to GCC. Either provide a string without the
|
||||
leading `-`, or a structured value `{flag : Str, arg: Str}`.
|
||||
"
|
||||
| List #GccFlag
|
||||
| default = [];
|
||||
| default = [],
|
||||
|
||||
optimizationLevel | doc "
|
||||
Optimization level. Possible values:
|
||||
@ -61,11 +60,11 @@ let Contract = {
|
||||
- *2*: use optimizations
|
||||
"
|
||||
| #OptLevel
|
||||
| default = 1;
|
||||
| default = 1,
|
||||
} in
|
||||
|
||||
// Use `nickel -f config_gcc.ncl` to see the resulting json.
|
||||
({
|
||||
flags = ["Wextra", {flag = "o"; arg = "stuff.o"}];
|
||||
optimizationLevel = 2;
|
||||
flags = ["Wextra", {flag = "o", arg = "stuff.o"}],
|
||||
optimizationLevel = 2,
|
||||
} | #Contract)
|
||||
|
@ -5,8 +5,8 @@ let myListLib = {
|
||||
// map and fold to be statically typed. This is due to a current issue with
|
||||
// the how the stdlib is typed, see
|
||||
// https://github.com/tweag/nickel/issues/226. It won't be needed eventually.
|
||||
head | forall a. List a -> a = fun l => %head% l;
|
||||
tail | forall a. List a -> List a = fun l => %tail% l;
|
||||
head | forall a. List a -> a = fun l => %head% l,
|
||||
tail | forall a. List a -> List a = fun l => %tail% l,
|
||||
|
||||
map : forall a b. (a -> b) -> List a -> List b = fun f list =>
|
||||
if list == [] then
|
||||
@ -14,14 +14,14 @@ let myListLib = {
|
||||
else
|
||||
let head = head list in
|
||||
let tail = tail list in
|
||||
[f head] @ map f tail;
|
||||
[f head] @ map f tail,
|
||||
|
||||
fold : forall a b. (a -> b -> b) -> List a -> b -> b =
|
||||
fun f list first =>
|
||||
if list == [] then
|
||||
first
|
||||
else
|
||||
f (head list) (fold f (tail list) first);
|
||||
f (head list) (fold f (tail list) first),
|
||||
} in
|
||||
// Compute `7!`
|
||||
let l = myListLib.map (fun x => x+1) [1, 2, 3, 4, 5, 6] in
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
server.host.ip = "182.168.1.1";
|
||||
server.host.port = 80;
|
||||
server.host.name = "hello-world.net";
|
||||
server.host.ip = "182.168.1.1",
|
||||
server.host.port = 80,
|
||||
server.host.name = "hello-world.net",
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
server.host.options = "TLS";
|
||||
server.host.options = "TLS",
|
||||
|
||||
firewall.enabled | default = true;
|
||||
firewall.type = "iptables";
|
||||
firewall.openPorts = [21,80,443];
|
||||
firewall.enabled | default = true,
|
||||
firewall.type = "iptables",
|
||||
firewall.openPorts = [21,80,443],
|
||||
}
|
||||
|
@ -1,15 +1,5 @@
|
||||
// An (incomplete and probably wrong) contract example for a Kubernetes
|
||||
// configuration element.
|
||||
|
||||
// There's a similar contract coming to the `nums` stdlib, but for now, we
|
||||
// redefine it. Similarly, in the future, common contracts such as `Port` or
|
||||
// `Url` will be provided by libraries.
|
||||
let PosNat | doc "A contract for a positive natural number" =
|
||||
fun label value =>
|
||||
if builtins.isNum value && value % 1 == 0 && value > 0 then
|
||||
value
|
||||
else
|
||||
contracts.blame label in
|
||||
// An illustrative (thus incomplete and maybe incorrect) contract example for a
|
||||
// Kubernetes configuration element.
|
||||
|
||||
let Port | doc "A contract for a port number" =
|
||||
fun label value =>
|
||||
@ -25,68 +15,69 @@ let Port | doc "A contract for a port number" =
|
||||
let PortElt
|
||||
| doc "A contract for a port element of a Kubernetes configuration"
|
||||
= {
|
||||
name | Str;
|
||||
containerPort | #Port;
|
||||
name | Str,
|
||||
containerPort | #Port,
|
||||
} in
|
||||
|
||||
let Container = {
|
||||
name | Str;
|
||||
image | Str;
|
||||
ports | List #PortElt;
|
||||
name | Str,
|
||||
image | Str,
|
||||
ports | List #PortElt,
|
||||
} in
|
||||
|
||||
let KubernetesConfig = {
|
||||
kind | <ReplicationController, ReplicaSet, Pod>
|
||||
| doc "The kind of the element being configured."
|
||||
| default = `Pod;
|
||||
| default = `Pod,
|
||||
|
||||
apiVersion | Str;
|
||||
apiVersion | Str,
|
||||
|
||||
metadata = {
|
||||
name | Str;
|
||||
labels.app | Str;
|
||||
};
|
||||
name | Str,
|
||||
labels.app | Str,
|
||||
},
|
||||
|
||||
spec = {
|
||||
replicas | #PosNat
|
||||
replicas | #(nums.PosNat)
|
||||
| doc "The number of replicas"
|
||||
| default = 1;
|
||||
| default = 1,
|
||||
|
||||
selector.matchLabels.app | Str;
|
||||
selector.matchLabels.app | Str,
|
||||
|
||||
template = {
|
||||
metadata.labels.app | Str;
|
||||
spec.containers | List #Container;
|
||||
};
|
||||
};
|
||||
metadata.labels.app | Str,
|
||||
spec.containers | List #Container,
|
||||
},
|
||||
},
|
||||
} in
|
||||
|
||||
let name_ = "myApp" in
|
||||
let metadata_ = {
|
||||
name = name_;
|
||||
labels.app = name_;
|
||||
name = name_,
|
||||
labels.app = name_,
|
||||
} in
|
||||
({
|
||||
kind = `ReplicationController;
|
||||
apiVersion = "1.1.0";
|
||||
metadata = metadata_;
|
||||
|
||||
{
|
||||
kind = `ReplicationController,
|
||||
apiVersion = "1.1.0",
|
||||
metadata = metadata_,
|
||||
spec = {
|
||||
replicas = 3;
|
||||
replicas = 3,
|
||||
selector = {
|
||||
app.name = name_;
|
||||
matchLabels.app = name_;
|
||||
};
|
||||
app.name = name_,
|
||||
matchLabels.app = name_,
|
||||
},
|
||||
template = {
|
||||
metadata = metadata_;
|
||||
metadata = metadata_,
|
||||
spec = {
|
||||
containers = [
|
||||
{
|
||||
name = name_;
|
||||
image = "k8s.gcr.io/#{name_}:v3";
|
||||
name = name_,
|
||||
image = "k8s.gcr.io/#{name_}:v3",
|
||||
ports = [
|
||||
{
|
||||
name = "http-server";
|
||||
containerPort = 80;
|
||||
name = "http-server",
|
||||
containerPort = 80,
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -94,5 +85,4 @@ let metadata_ = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
| #KubernetesConfig)
|
||||
} | #KubernetesConfig
|
||||
|
Loading…
Reference in New Issue
Block a user