From 8a1ab709a47f0896cb5b47521e31c8c27f88b2b3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 22 Sep 2006 14:31:55 +0000 Subject: * New builtin functions builtins.{hasAttr, getAttr} to check for attribute existence and to return an attribute from an attribute set, respectively. Example: `hasAttr "foo" {foo = 1;}'. They differ from the `?' and `.' operators in that the attribute name is an arbitrary expression. (NIX-61) --- tests/lang/eval-okay-attrs2.exp | 1 + tests/lang/eval-okay-attrs2.nix | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/lang/eval-okay-attrs2.exp create mode 100644 tests/lang/eval-okay-attrs2.nix (limited to 'tests') diff --git a/tests/lang/eval-okay-attrs2.exp b/tests/lang/eval-okay-attrs2.exp new file mode 100644 index 000000000000..add36384d296 --- /dev/null +++ b/tests/lang/eval-okay-attrs2.exp @@ -0,0 +1 @@ +Int(987) \ No newline at end of file diff --git a/tests/lang/eval-okay-attrs2.nix b/tests/lang/eval-okay-attrs2.nix new file mode 100644 index 000000000000..9e06b83ac1fd --- /dev/null +++ b/tests/lang/eval-okay-attrs2.nix @@ -0,0 +1,10 @@ +let { + as = { x = 123; y = 456; } // { z = 789; } // { z = 987; }; + + A = "a"; + Z = "z"; + + body = if builtins.hasAttr A as + then builtins.getAttr A as + else assert builtins.hasAttr Z as; builtins.getAttr Z as; +} -- cgit 1.4.1