I have a domain of strings and I want to test for an elements. The find seems to be what I want, but it's giving me an error.
var names: domain(string);
names += "bob";
if !names.find("bob") {
writeln("Where is Bob?")
}
produces an error
error: illegal access of iterator or promoted expression
To check for membership within a domain, you want to use domain.member():
if !names.member("bob") {
writeln("Where is Bob?")
}
As for your original example, there is no domain.find(), so your original example is actually getting promoted to string.find() on each element of the domain. #8450 describes this in more detail.
Related
Example error print of a unit test:
Expected
<string>: "...up - Finish..."
to equal |
<string>: "...up - Vault ..."
Is there a way to increase the print limit this is just not practical at all...
Like at least to something like 100 signs...
Edit:
I might not have given enough information:
Vault ...
Finish...
Are not the only parts that are different in the string and it is very hard to read without more context if an error occurs. There should be a way to allow full comparison prints no? Similar as to how it is in NodeJS Chai.
I do not believe this is possible without modifying the underlying Ginkgo code, at least from my reading and experimentation. Ginkgo uses its own reporting framework, and you can leverage that to customize the output...within limits.
One way to see the raw report output is to dump it as json with the --json-report <PATH> flag for ginkgo:
$ ginkgo --json-report=spec-out.json
I created a simple spec that compared two really long strings (just the English alphabet repeated, separated by spaces, a bunch of times), differing only in the replacement of a single alphabet block with "foobar", and the contents of the report relevant to what you'd see in the normal output were limited to:
"Failure": {
"Message": "Expected\n \u003cstring\u003e: \"...wxyz abcdef...\"\nto equal |\n \u003cstring\u003e: \"...wxyz foobar...\"",
Then I changed the compared string so that it the diff extended for a much longer stretch, and the message was identical - still truncated to the initial point of mismatch.
You can access the underlying reporting framework through Ginkgo itself, for example:
ReportAfterEach(func(report SpecReport) {
fmt.Fprintf(os.Stderr, "SPEC REPORT: %s | %s\nFAILURE MESSAGE: %s\n", report.State, report.FullText(), report.FailureMessage())
})
This also returned the truncated strings in the message, which would indicate to me that there is no easily accessible mechanism for getting a longer string to output - since this is presumably generated at a lower level (I'm thinking in the code for the Equal() matcher, but I haven't looked yet):
SPEC REPORT: failed | Utils Compares really long strings
FAILURE MESSAGE: Expected
<string>: "...wxyz abcdef..."
to equal |
<string>: "...wxyz foobar..."
For reference see the ginkgo reporting docs and relevant portion of the ginkgo godoc.
I am trying to use nginx caching features, however we have and endpoint that uses latitude and longitude, so for that, to increase the cache hit ratio, we have to truncate lat and long.
I created a map to ignore last two latitude digits. The problem is the map isn't working, it always returns the original latitude (45.45452).
Consider $arg_latitude being 45.45452, the expected result is 45.45.
map $arg_latitude $rounded_latitude {
default $arg_latitude;
~\d+\.\d\d $arg_latitude;
}
Any idea why isn't working?
The result of your map is always the original value of $arg_latitude, because that is the value that you have inserted in the right hand column.
You need to add a capture to your regular expression and use that as the new value.
For example:
map $arg_latitude $rounded_latitude {
default $arg_latitude;
~^(?<rounded>\d+\.\d\d) $rounded;
}
Use of a named capture is recommended, as a numeric capture may not be in-scope at the point where $rounded_latitude is evaluated.
See this document for more.
I want to pass into a variable, the language of the user.
But, my client can't/didn't pass this information trough datalayer. So, the unique solution I've is to use the URL Path.
Indeed - The structure is:
http://www.website.be/en/subcategory/subsubcategory
I want to extract "en" information
No idea to get this - I check on Stack, on google, some people talk about regex, other ones about CustomJS, but, no result on my specific setup.
Do you have an idea how to proceed on this point ?
Many thanks !!
Ludo
Make sure the built in {{Page Path}} variable is enabled. Create a custom Javascript variable.
function() {
var parts = {{Page Path}}.split("/");
return parts[1];
}
This splits the path by the path delimiter "/" and gives you an array with the parts. Since the page path has a leading slash (I think), the first part is empty, so you return the second one (since array indexing starts with 0 the second array element has the index 1).
This might need a bit of refinement (for pages that do not start with a language signifier, if any), but that's the basic idea.
Regex is an alternative (via the regex table variable), but the above solution is a little easier to implement.
I use DDMathParser to solver formula expressions using Swift. The following code works fine, however, implicit multiplication doesn't. Reading the docs it should work... So, what do I miss here?
my code:
...
substitutions.updateValue(3, forKey: "x")
let myString = "3$x"
do{
let expression = try Expression(string: myString, operatorSet: operatorSet, options: myTRO, locale: myLocale)
let result = try evaluator.evaluate(expression, substitutions: substitutions)
print("expression is: \(expression), the result is : \(result)")
} catch {
print("Error")
}
...
The code throws the "Error". Using the string "3*$x" the expression is calculated as expected.
DDMathParser author here.
So, the .invalidFormat error is thrown when the framework has a sequence of tokens and is looking for an operator in order to figure out what goes around it. If it can't find an operator but still has tokens to resolve but no operator, then it throws the .invalidFormat error.
This implies that you have a 3.0 number token and a $x variable token, but no × multiplication token.
I see also that you're passing in a custom set of TokenResolverOptions (the myTRO variable). I'd guess that you're passing in an option set that does not include the .allowImplicitMultiplication value. If I try to parse 3$x without the .allowImplicitMultiplication resolver option, then I get the .invalidFormat error thrown.
Ok, got it myself. As Dave DeLong mentioned .allowImplicitMultiplication is included by default in the options but will get ignored when creating custom options. Since I want to use localized expressions (decimal separator within expression string is local) I need to use the advanced definition of Expression:
let expression = try Expression(string: ..., operatorSet: ..., options: ..., locale: ...)
In order to use the localized string option I defined let myLocale = NSLocale.current but accidentally also created a new operatorSet new options and passed it to the expression definition. The right way is not to create custom operatorSet and options but to use the defaults within the Expression definition:
let expression = try Expression(string: expressionString, operatorSet: OperatorSet.default, options: TokenResolverOptions.default, locale: myLocale)
Dave DeLong did a really great job in creating the DDMatParser framework. For newbies it is very hard to get started with. The wiki section at DDMathParser is pretty basic and doesn't give some details or examples for all the other great functionality DDMatParser is providing.
I have been trying to understand why some regular expressions give me an error "Unknown tag" while using the validator.v2 package in golang. It works for some regular expressions but does not work with some which have "{}" inside them, and when I use the validator.Validate() it gives me an error at runtime "unknown tag".
Here's the code:
type Company struct {
Name string `validate:"regexp=^[a-zA-Z .]{1,100}$"`
}
which gives me the following error at runtime:
Name: unknown tag
however this regex works perfectly fine
type Company struct {
Name string `validate:"regexp=^[a-zA-Z .]*$"`
}
I am using the braces because of length restrictions that I want to put on the string. There could be other ways to do it, but I feel the regex is the way to go and is easier to have it along with other rules right there in the expression.
The problem appears to be the , char in your first regex. You can see in the validator source code that the tag is split on ,. By UTSLing, I see no support for escaped commas in the tags; this is probably an oversight on the part of the project author. I suggest filing a bug/feature request.
The problem pointed out by #Flimzy is correct, but it's not a bug.
Probably it was fixed since then, so at the moment validator supports escape sequence \\ for such case, and you can do it like this:
type Company struct {
Name string `validate:"regexp=^[a-zA-Z .]{1\\,100}$"`
}