matcher

Jasmine toEqual for complex objects (mixed with functions)

血红的双手。 提交于 2019-11-27 17:29:56
问题 Currently, I have a function that sometimes return an object with some functions inside. When using expect(...).toEqual({...}) it doesn't seem to match those complex objects. Objects having functions or the File class (from input type file), it just can't. How to overcome this? 回答1: Try the Underscore _.isEqual() function: expect(_.isEqual(obj1, obj2)).toEqual(true); If that works, you could create a custom matcher: this.addMatchers({ toDeepEqual: function(expected) { return _.isEqual(this

Java Pattern Matcher: create new or reset?

故事扮演 提交于 2019-11-27 14:59:53
Assume a Regular Expression , which, via a Java Matcher object, is matched against a large number of strings: String expression = ...; // The Regular Expression Pattern pattern = Pattern.compile(expression); String[] ALL_INPUT = ...; // The large number of strings to be matched Matcher matcher; // Declare but not initialize a Matcher for (String input:ALL_INPUT) { matcher = pattern.matcher(input); // Create a new Matcher if (matcher.matches()) // Or whatever other matcher check { // Whatever processing } } In the Java SE 6 JavaDoc for Matcher , one finds the option of reusing the same Matcher

Why doesn't this code attempting to use Hamcrest's hasItems compile?

浪尽此生 提交于 2019-11-27 12:33:08
Why does this not compile, oh, what to do? import static org.junit.Assert.assertThat; import static org.junit.matchers.JUnitMatchers.hasItems; ArrayList<Integer> actual = new ArrayList<Integer>(); ArrayList<Integer> expected = new ArrayList<Integer>(); actual.add(1); expected.add(2); assertThat(actual, hasItems(expected)); error copied from comment: cannot find symbol method assertThat(java.util.ArrayList<java.lang.Integer>, org.hamcreset.Matcher<java.lang.Iterable<java.util.ArrayList<java.lang.Integer>>>) Clive Evans Just ran into this post trying to fix it for myself. Gave me just enough

Convert Javascript regular expression to Java syntax

*爱你&永不变心* 提交于 2019-11-27 10:55:36
问题 I am aware that regEx are common across languages...But I am having trouble in writing the Java syntax. I have a regular expression coded in JS as; if((/[a-zA-Z]/).test(str) && (/[0-9]|[\x21-\x2F|\x3A-\x40|\x5B-\x60|\x7B-\x7E]/).test(str)) return true; How do I write the same in Java ? I have imported import java.util.regex.Matcher; import java.util.regex.Pattern; Just to add, from what I am trying it is saying \x is an invalid escape character.. 回答1: Change the leading and trailing '/'

When to use ** (double star) in glob syntax within JAVA

浪子不回头ぞ 提交于 2019-11-27 09:46:28
问题 Directly from this Java Oracle tutorial: Two asterisks, **, works like * but crosses directory boundaries. This syntax is generally used for matching complete paths. Could anybody do a real example out of it? What do they mean with "crosses directory boundary"? Crossing the directory boundary, I imagine something like checking the file from root to getNameCount()-1 . Again a real example explaining the difference between * and ** in practice would be great. 回答1: The javadoc for FileSystem

Replace HTML codes with equivalent characters in Java [duplicate]

心不动则不痛 提交于 2019-11-27 09:05:14
This question already has an answer here: How to unescape HTML character entities in Java? 10 answers Currently I'm working on converting HTML codes with equivalent characters in java. I need to convert the below code to characters. è - è ® - ® & - & ñ - ñ & - & I tried using the regex pattern (&#x)([\\d|\\w]*)([\\d|\\w]*)([\\d|\\w]*)([\\d|\\w]*)(;) When I debug, matcher.find() gives me true but the control skips the loop where I have written the code for conversion. Don't know what is happening there. Also, is there any way to optimize this regex? Any help is appreciated. Exception java.lang

Java regex to match start/end tags causes stack overflow

[亡魂溺海] 提交于 2019-11-27 05:38:42
The standard implementation of the Java Pattern class uses recursion to implement many forms of regular expressions (e.g., certain operators, alternation). This approach causes stack overflow issues with input strings that exceed a (relatively small) length, which may not even be more than 1,000 characters, depending on the regex involved. A typical example of this is the following regex using alternation to extract a possibly multiline element (named Data ) from a surrounding XML string, which has already been supplied: <Data>(?<data>(?:.|\r|\n)+?)</Data> The above regex is used in with the

What's the difference between Mockito Matchers isA, any, eq, and same?

流过昼夜 提交于 2019-11-27 05:32:11
问题 I am confused on what's the difference between them, and which one to choose in which case. Some difference might be obvious, like any and eq , but I'm including them all just to be sure. I wonder about their differences because I came across this problem: I have this POST method in a Controller class public Response doSomething(@ResponseBody Request request) { return someService.doSomething(request); } And would like to perform a unit test on that controller. I have two versions. The first

How Matcher.find() works [duplicate]

邮差的信 提交于 2019-11-27 03:52:33
问题 This question already has an answer here: SCJP6 regex issue 1 answer I am testing a small stub of Matcher and Pattern class...see the following small stub.. package scjp2.escape.sequence.examples; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Sample_19 { public static void main(String a[]){ String stream = "ab34ef"; Pattern pattern = Pattern.compile("\\d*"); //HERE * IS GREEDY QUANTIFIER THAT LOOKS FOR ZERO TO MANY COMBINATION THAT //START WITH NUMBER Matcher

PatternSyntaxException: Illegal Repetition when using regex in Java

会有一股神秘感。 提交于 2019-11-27 01:47:21
I don't know much regex, but I need to match a simple pattern. The following should return true, Pattern.matches("{\"user_id\" : [0-9]*}", inputLine) when inputLine is {"user_id" : 34} However, I'm getting this exception: java.util.regex.PatternSyntaxException: Illegal repetition {"user_id" : 24} at java.util.regex.Pattern.error(Unknown Source) at java.util.regex.Pattern.closure(Unknown Source) at java.util.regex.Pattern.sequence(Unknown Source) at java.util.regex.Pattern.expr(Unknown Source) at java.util.regex.Pattern.compile(Unknown Source) at java.util.regex.Pattern.<init>(Unknown Source)