text:
package com.jetbrains.python.parsing;

import com.intellij.lang.LanguageASTFactory;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.testFramework.ParsingTestCase;
import com.intellij.testFramework.TestDataPath;
import com.jetbrains.python.*;
import com.jetbrains.python.psi.LanguageLevel;
import com.jetbrains.python.psi.PyFunction;
import com.jetbrains.python.psi.PyPsiFacade;
import com.jetbrains.python.psi.impl.PyPsiFacadeImpl;
import com.jetbrains.python.psi.impl.PythonASTFactory;
import com.jetbrains.python.psi.impl.PythonLanguageLevelPusher;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;

@TestDataPath("$CONTENT_ROOT/../testData/psi/")
public class PythonParsingTest extends ParsingTestCase {
  private LanguageLevel myLanguageLevel = LanguageLevel.getDefault();

  @SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors")
  public PythonParsingTest() {
    this(new PythonParserDefinition());
  }

  protected PythonParsingTest(PythonParserDefinition parserDefinition) {
    super("psi", "py", parserDefinition);
  }

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    Registry.markAsLoaded();
    registerExtensionPoint(PythonDialectsTokenSetContributor.EP_NAME, PythonDialectsTokenSetContributor.class);
    registerExtension(PythonDialectsTokenSetContributor.EP_NAME, new PythonTokenSetContributor());
    addExplicitExtension(LanguageASTFactory.INSTANCE, PythonLanguage.getInstance(), new PythonASTFactory());
    getProject().registerService(PyPsiFacade.class, PyPsiFacadeImpl.class);
  }

  @Override
  protected String getTestDataPath() {
    return PythonHelpersLocator.getPythonCommunityPath() + "/testData";
  }

  public void testHelloWorld() {
    doTest();
  }

  public void testIfStatement() {
    doTest();
  }

  public void testConditionalExpression() {
    doTest();
  }

  public void testSubscribedAssignmentLHS() {
    doTest();
  }

  public void testConditionalParenLambda() {
    doTest();
  }

  public void testLambdaComprehension() {
    doTest();
  }

  public void testLambdaConditional() {
    doTest();
  }

  public void testTryExceptFinally() {
    doTest();
  }

  public void testTryFinally() {
    doTest();
  }

  public void testYieldStatement() {
    doTest();
  }

  public void testYieldInAssignment() {
    doTest();
  }

  public void testYieldInAugAssignment() {
    doTest();
  }

  public void testYieldInParentheses() {
    doTest();
  }

  public void _testYieldAsArgument() {
    // this is a strange case: PEP 342 says this syntax is valid, but
    // Python 2.5 doesn't accept it. let's stick with Python behavior for now
    doTest();
  }

  public void testWithStatement() {
    doTest();
  }

  public void testDecoratedFunction() {
    doTest();
  }

  public void testTryExceptAs() {   // PY-293
    doTest();
  }

  public void testWithStatement26() {
    doTest(LanguageLevel.PYTHON26);
  }

  public void testPrintAsFunction26() {
    doTest(LanguageLevel.PYTHON26);
  }

  public void testClassDecorators() {
    doTest(LanguageLevel.PYTHON26);
  }

  public void testEmptySuperclassList() {  // PY-321
    doTest();
  }

  public void testListComprehensionNestedIf() {  // PY-322
    doTest();
  }

  public void testKeywordOnlyArgument() {   // PEP 3102
    doTest(LanguageLevel.PYTHON34);
  }

  public void testPy3KKeywords() {
    doTest(LanguageLevel.PYTHON34);
  }

  public void testExecPy2() {
    doTest();
  }

  public void testExecPy3() {
    doTest(LanguageLevel.PYTHON34);
  }

  public void testSuperclassKeywordArguments() {
    doTest(LanguageLevel.PYTHON34);
  }

  public void testDictLiteral() {
    doTest();
  }

  public void testSetLiteral() {
    doTest(LanguageLevel.PYTHON34);
  }

  public void testSetComprehension() {
    doTest(LanguageLevel.PYTHON34);
  }

  public void testDictComprehension() {
    doTest(LanguageLevel.PYTHON34);
  }

  public void testRaiseFrom() {
    doTest(LanguageLevel.PYTHON34);
  }

  public void testEllipsis() {
    doTest();
  }

  public void testTupleArguments() {
    doTest();
  }

  public void testDefaultTupleArguments() {
    doTest();
  }

  public void testExtendedSlices() {
    doTest();
  }

  public void testAnnotations() {
    doTest(LanguageLevel.PYTHON34);
  }

  public void testNonlocal() {
    doTest(LanguageLevel.PYTHON34);
  }

  public void testFloorDiv() {
    doTest();
  }

  public void testWithStatement31() {
    doTest(LanguageLevel.PYTHON34);
  }

  public void testLongString() {
    doTest();
  }

  public void testTrailingSemicolon() {  // PY-363
    doTest();
  }

  public void testStarExpression() {   // PEP-3132
    doTest(LanguageLevel.PYTHON34);
  }

  public void testDictMissingComma() {  // PY-1025
    doTest();
  }

  public void testInconsistentDedent() { // PY-1131
    doTest();
  }

  public void testReturnAtEOF() {  // PY-1739
    doTest();
  }

  public void testMissingListSeparators() {  // PY-1933
    doTest();
  }

  public void testTrailingCommaInList() {
    doTest();
  }

  public void testCommentBeforeMethod() { // PY-2209 & friends
    doTest();
  }

  public void testBadDecoratorNotMethod() {
    doTest();
  }

  public void testCommentAtEndOfMethod() { // PY-2137
    doTest();
  }

  public void testCommentAtBeginningOfStatementList() {  // PY-2108
    doTest();
  }

  public void testCommentBetweenClasses() {  // PY-1598
    doTest();
  }

  public void testIncompleteDict() {
    doTest();
  }

  public void testSliceList() {  // PY-1928
    doTest();
  }

  public void testDictMissingValue() {  // PY-2791
    doTest();
  }

  public void testColonBeforeEof() {  // PY-2790
    doTest();
  }

  public void testGeneratorInArgumentList() {  // PY-3172
    doTest();
  }

  public void testNestedGenerators() {  // PY-3030
    doTest();
  }

  public void testMissingDefaultValue() {  // PY-3253
    doTest();
  }

  public void testErrorInParameterList() {  // PY-3635
    doTest();
  }

  public void testKeywordAsDefaultParameterValue() {  // PY-3713
    doTest();
  }

  public void testTrailingCommaInArgList() {  // PY-4016
    doTest();
  }

  public void testMissingParenInCall() {  // PY-4053
    doTest();
  }

  public void testTupleAsDictKey() {  // PY-4144
    doTest();
  }

  public void testIncompleteStatementList() {  // PY-3792
    doTest();
  }

  public void testIncompleteFor() {  // PY-3792
    doTest();
  }

  public void testCallInAssignment() {  // PY-5062
    doTest();
  }

  public void testCommaAfterStarArg() {  // PY-4039
    doTest();
  }

  // PY-24389
  public void testCommaAfterStarArgAllowedInPython36() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testRangeAsLHS() {  // PY-6468
    doTest();
  }

  // PY-6702
  public void testYieldFrom() {
    doTest(LanguageLevel.PYTHON34);
  }

  // PY-6733
  public void testYieldFromNoExpr() {
    doTest(LanguageLevel.PYTHON34);
  }

  // PY-6734
  public void testRaiseFromNoExpr() {
    doTest(LanguageLevel.PYTHON34);
  }

  // PY-6781
  public void testComprehensionErrors() {
    doTest();
  }

  // PY-6926
  public void testGeneratorList() {
    doTest();
  }

  // EA-30244
  public void testEqYieldEq() {
    doTest();
  }

  public void testCompoundStatementAfterSemicolon() {  // PY-7660
    doTest();
  }

  // PY-8606
  public void testEllipsisInSliceList() {
    doTest();
  }

  // PY-8606
  public void testEllipsisInSliceListTail() {
    doTest();
  }

  public void testEmptySubscription() {  // PY-8652
    doTest();
  }

  // PY-8752
  public void testEllipsisPython3() {
    doTest(LanguageLevel.PYTHON34);
  }

  // PY-8948
  public void testNotClosedSlice() {
    doTest();
  }

  // PY-11058
  public void testResetAfterSemicolon() {
    doTest();
  }

  public void testLoneStar() {  // PY-10177
    doTest();
  }

  public void testCommentAfterDecorator() {  // PY-5912
    doTest();
  }

  public void testKeywordAsNamedParameter() {  // PY-8318
    doTest();
  }

  public void testKeywordAsClassName() {  // PY-8319
    doTest();
  }

  public void testKeywordAsFunctionName() {  // PY-8319
    doTest();
  }

  public void testIfInList() {  // PY-9561
    doTest();
  }

  public void testWithMissingID() {  // PY-9853
    doTest(LanguageLevel.PYTHON27);
  }

  public void testOverIndentedComment() {  // PY-1909
    doTest();
  }

  public void testNotClosedBraceDict() {
    doTest();
  }

  public void testNotClosedBraceSet() {
    doTest(LanguageLevel.PYTHON34);
  }

  public void testEmptyBlockInFunctionBeforeFunction() {
    doTest();
  }

  public void testBlockWithoutColon() {
    doTest();
  }

  public void testSingleDefBeforeFunction() {
    doTest();
  }

  public void testSingleClassBeforeFunction() {
    doTest();
  }

  // PY-14408
  public void testTabInsideContinuationIndent() {
    doTest();
  }

  // PY-15390
  public void testMatMul() {
    doTest(LanguageLevel.PYTHON35);
  }

  // PY-15653
  public void testMissingFunctionNameAndThenParametersList() {
    doTest();
  }

  // PY-15653
  public void testMissingClassNameAndThenListOfBaseClasses() {
    doTest();
  }

  // PY-15653
  public void testMissingClassNameAndThenColon() {
    doTest();
  }

  public void testAsyncDef() {
    doTest(LanguageLevel.PYTHON35);
  }

  public void testAsyncWith() {
    doTest(LanguageLevel.PYTHON35);
  }

  public void testAsyncFor() {
    doTest(LanguageLevel.PYTHON35);
  }

  public void testAwait() {
    doTest(LanguageLevel.PYTHON35);
  }

  public void testDecoratedAsyncDef() {
    doTest(LanguageLevel.PYTHON35);
  }

  public void testFStrings() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testEmptyFStrings() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringWithSimpleFragment() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringGluedWithLiteralStringNodes() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringEscapedBraces() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringExpressionContainBraces() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringFragmentWithLiteralFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringFragmentWithInterpolatedFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringFragmentWithNotParenthesizedLambda() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringFragmentWithParenthesizedLambda() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringFragmentWithDictLiteral() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringFragmentTypeConversion() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringFragmentIllegalTypeConversion() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringFragmentIncompleteTypeConversionBeforeColon() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringFragmentIncompleteTypeConversionBeforeClosingBrace() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringFragmentIncompleteTypeConversionBeforeClosingQuote() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringFragmentTypeConversionAfterFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringFragmentDuplicateTypeConversion() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringIncompleteFragment() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringIncompleteFragmentWithTypeConversion() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringIncompleteFragmentWithFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringIncompleteFragmentWithTypeConversionAndFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteOfStringLiteral() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteInsideStringLiteral() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteOfNestedStringLiteral() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteInsideNestedStringLiteral() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteOfFStringLiteral() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteInsideFStringLiteral() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteOfNestedFStringLiteral() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteInsideNestedFStringLiteral() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteOfStringLiteralInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteInsideStringLiteralInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteOfNestedStringLiteralInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteInsideNestedStringLiteralInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteOfFStringLiteralInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteInsideFStringLiteralInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteOfNestedFStringLiteralInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteInsideNestedFStringLiteralInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteInLiteralPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteInNestedLiteralPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByQuoteInNestedFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByLineBreakInLiteralPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByLineBreakInNestedLiteralPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByLineBreakInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByLineBreakInNestedFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByLineBreakInExpression() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByLineBreakInNestedExpression() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByLineBreakInExpressionInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByLineBreakInNestedExpressionInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByLineBreakInStringLiteral() {
    doTest(LanguageLevel.PYTHON36);
  }

  // not possible to come up with such case without escaping: triple-quoted string inside
  // two nested f-strings with different types of quotes
  public void testFStringTerminatedByEscapedLineBreakInNestedStringLiteral() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByLineBreakInStringLiteralInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTerminatedByLineBreakInNestedStringLiteralInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testMultilineFStringTerminatedByQuotesOfStringLiteral() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testMultilineFStringTerminatedByQuotesInsideParenthesizedExpression() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testMultilineFStringContainingMultilineExpression() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testMultilineFStringContainingMultilineExpressionAfterStatementBreak() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testNestedMultilineFStringsWithMultilineExpressions() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testSingleQuotedFStringInsideMultilineFStringTerminatedByLineBreakInText() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testSingleQuotedFStringInsideMultilineFStringTerminatedByLineBreakInExpression() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testSingleQuotedFStringInsideMultilineFStringTerminatedByLineBreakInExpressionInParentheses() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringAllKindsNested() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringBackslashInsteadOfExpression() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringBackslashAfterExpression() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringBackslashBeforeExpression() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringBackslashInsideMultilineExpression() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testSingleLineFStringContainsCommentInsideExpression() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testSingleLineFStringContainsCommentInsteadOfExpression() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringContainsHashSignInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringContainsHashInLiteralPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testUnterminatedFStringWithTrailingBackslashInLiteralPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testUnterminatedFStringWithTrailingBackslashInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testMultilineFStringContainsCommentInsideExpression() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testMultilineFStringContainsCommentInsteadOfExpression() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringNamedUnicodeEscapeInLiteralPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringIncompleteNamedUnicodePrecedingFragment() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringNamedUnicodeEscapeInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringNamedUnicodeEscapeInStringLiteral() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringEscapeSequenceInLiteralPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringEscapeSequenceInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringEscapedSlashBeforeClosingQuoteInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringSingleSlashBeforeLeftBraceInLiteralPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringSingleSlashesBeforeBracesInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringEscapedLineBreakInLiteralPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringDeeplyNestedEmptyFragments() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTrailingWhitespaceInIncompleteFragmentInFormatPart() {
    doTest(LanguageLevel.PYTHON36);
  }

  // PY-32123
  public void testFStringRawFStringInsidePlainFString() {
    doTest(LanguageLevel.PYTHON36);
  }

  // PY-32123
  public void testFStringPlainInsideRawFString() {
    doTest(LanguageLevel.PYTHON36);
  }

  // PY-32123
  public void testFStringEscapeInFormatPartOfRawLiteral() {
    doTest(LanguageLevel.PYTHON36);
  }

  // PY-32123
  public void testFStringEscapeInFormatPartOfPlainLiteral() {
    doTest(LanguageLevel.PYTHON36);
  }

  public void testFStringTextTokenMerging() {
    doTest(LanguageLevel.PYTHON36);
  }

  // PY-19036
  public void testAwaitInNonAsyncNestedFunction() {
    doTest(LanguageLevel.PYTHON35);
  }

  public void testUnpackingExpressions() {
    doTest(LanguageLevel.PYTHON35);
  }

  public void testVariableAnnotations() {
    doTest(LanguageLevel.PYTHON36);
  }

  // PY-20770
  public void testAsyncComprehensions() {
    doTest(LanguageLevel.PYTHON36);
  }

  // PY-20770
  public void testAwaitInComprehensions() {
    doTest(LanguageLevel.PYTHON36);
  }

  // PY-20682
  public void testAwaitOnTheSameLineAsFor() {
    doTest(LanguageLevel.PYTHON35);
  }

  // PY-17017
  public void testTrailingBlockCommentsAtEndOfFile() {
    doTest();
  }

  // PY-17017
  public void testTrailingBlockCommentsFollowedByStatement() {
    doTest();
  }

  // PY-35512
  public void testPositionalOnlyParameters() {
    doTest(LanguageLevel.PYTHON38);
  }

  // PY-36009
  public void testFStringEqualitySign() {
    doTest(LanguageLevel.PYTHON37);
  }

  // PY-33886
  public void testAssignmentExpressions() {
    doTest(LanguageLevel.PYTHON38);
  }

  // PY-33886
  public void testInvalidAssignmentExpressions() {
    doTest(LanguageLevel.PYTHON38);
  }

  // PY-33886, PY-36478
  public void testInvalidNonParenthesizedAssignmentExpressions() {
    doTest(LanguageLevel.getLatest());
  }

  // PY-33886
  public void testAssignmentExpressionsInFString() {
    doTest(LanguageLevel.PYTHON38);
  }

  // PY-36167
  public void testFunctionWithPassAndAwaitAfterInPy36() {
    doTest(LanguageLevel.PYTHON36);
  }

  // PY-41305
  public void testExpressionsInDecorators() {
    doTest(LanguageLevel.getLatest());
  }

  public void testPatternMatchingMatchAndCaseKeywordsFollowedByNamesakeIdentifiers() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingMatchLooksLikeBinaryExpression() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingMatchLooksLikeCallWithMultipleArguments() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingMatchLooksLikeCallWithSingleArgument() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingMatchLooksLikeCallWithoutArguments() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingMatchLooksLikeIndexing() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingLiteralPatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryFStringsInLiteralPatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryIllegalNumericExpressionsInLiteralPatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryNoSubjectAfterMatch() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryNoPatternAfterCase() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryNoPatternAfterCaseInIntermediateCaseClause() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryIllegalStatementsInsideMatch() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryDanglingBracketsInNestedPatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryMatchStatementWithoutClauses() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryMatchStatementWithoutClausesWithComment() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryMatchStatementWithoutClausesAtEndOfFile() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryMatchStatementWithoutClausesWithCommentAtEndOfFile() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingSingleCapturePattern() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingSingleValuePattern() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingValuePatternStartingWithUnderscore() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryIncompleteValuePattern() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingSingleWildcardPattern() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingGroupAndParenthesizedSequencePatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryIncompleteGroupAndParenthesizedSequencePatterns() {
    // XXX Missing statement breaks after "pass" here are odd
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingSequencePatternsInBrackets() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryIncompleteSequencePatternsInBrackets() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoverySequencePatternsMissingCommas() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoverySequenceAndGroupPatternsFollowedByIllegalContent() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryIllegalExpressionInSequencePatternItem() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingStarPatternsInSequences() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryStarPatternMissingIdentifier() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryStarPatternFollowedByQualifiedReference() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingMatchStatementFollowedByAnotherStatement() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryExtraCommasInSequencePatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingMappingPatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryIncompleteMappingPatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryExtraCommasInMappingPatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryDoubleStarWildcardPattern() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingClassPatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryIncompleteClassPatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryExtraCommasInClassPatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryClassPatternsFollowedByIllegalContent() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingOrPatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryIncompleteOrPatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryExtraBarsInOrPatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingAsPatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryIncompleteAsPatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryAsPatternAsOrPatternComponent() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryAsPatternsWithIllegalTarget() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingTopLevelSequencePatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryExtraCommasInTopLevelSequencePatterns() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingCaseGuards() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingRecoveryIncompleteCaseGuards() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void testPatternMatchingLeadingAndTrailingComments() {
    doTest(LanguageLevel.PYTHON310);
  }

  public void doTest() {
    doTest(LanguageLevel.PYTHON26);
  }

  public void doTest(LanguageLevel languageLevel) {
    LanguageLevel prev = myLanguageLevel;
    myLanguageLevel = languageLevel;
    try {
      doTest(true);
    }
    finally {
      myLanguageLevel = prev;
    }
    ensureEachFunctionHasStatementList(myFile, PyFunction.class);
  }

  @Override
  protected PsiFile createFile(@NotNull String name, @NotNull String text) {
    final PsiFile file = super.createFile(name, text);
    PythonLanguageLevelPusher.specifyFileLanguageLevel(file.getVirtualFile(), myLanguageLevel);
    return file;
  }

  public static <T extends PyFunction> void ensureEachFunctionHasStatementList(
    @NotNull PsiFile parentFile,
    @NotNull Class<T> functionType) {
    Collection<T> functions = PsiTreeUtil.findChildrenOfType(parentFile, functionType);
    for (T functionToCheck : functions) {
      functionToCheck.getStatementList(); //To make sure each function has statement list (does not throw exception)
    }
  }

}


text:
package org.sagebionetworks.web.client.place;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;
import java.util.LinkedList;
import org.sagebionetworks.web.client.StringUtils;

public class Synapse extends Place {

  public static final String DOT_REGEX = "\\.";
  public static final String DELIMITER = "/";
  public static final String SYNAPSE_ENTITY_PREFIX = "#!Synapse:";
  public static final String VERSION = "version";

  private String synapsePlaceToken;
  private String entityId, areaToken;
  private Long versionNumber;
  private Synapse.EntityArea area;

  public Synapse(String token) {
    this.synapsePlaceToken = token;
    area = null;
    areaToken = null;
    String[] tokensArray = token.split(DELIMITER);
    LinkedList<String> tokens = new LinkedList<String>();
    for (int i = 0; i < tokensArray.length; i++) {
      tokens.add(tokensArray[i]);
    }

    // first token should be the entity id
    entityId = tokens.poll();

    // look for dot version syntax in this token
    String[] entityIdTokens = entityId.split(DOT_REGEX);
    if (entityIdTokens.length > 1) {
      entityId = entityIdTokens[0];
      try {
        versionNumber = Long.parseLong(entityIdTokens[1]);
      } catch (NumberFormatException e) {
        // invalid version, ignore
      }
    }

    // set the next token
    String nextToken = tokens.poll();

    if (nextToken != null && VERSION.equals(nextToken.toLowerCase())) {
      nextToken = null;
      if (!tokens.isEmpty()) {
        try {
          versionNumber = Long.parseLong(tokens.removeFirst());
        } catch (NumberFormatException e) {
          // invalid version, ignore
        }
        nextToken = tokens.poll();
      }
    }

    if (nextToken != null) {
      try {
        area = EntityArea.valueOf(nextToken.toUpperCase());
      } catch (Exception e) {
        // invalid entity area, ignore
      }
    }

    // remaining tokens are recognized is the area token
    if (tokens.size() > 0) {
      areaToken = "";
    }
    while (tokens.size() > 0) {
      areaToken += tokens.poll();
      if (tokens.size() > 0) {
        areaToken += "/";
      }
    }
  }

  public static String getDelimiter(Synapse.EntityArea tab) {
    return "/" + tab.toString().toLowerCase() + "/";
  }

  public Synapse(
    String entityId,
    Long versionNumber,
    Synapse.EntityArea area,
    String areaToken
  ) {
    this.entityId = entityId;
    this.versionNumber = versionNumber;
    this.area = area;
    this.areaToken = areaToken;
    calculateToken(entityId, versionNumber, area, areaToken);
  }

  private void calculateToken(
    String entityId,
    Long versionNumber,
    Synapse.EntityArea area,
    String areaToken
  ) {
    this.synapsePlaceToken = entityId;
    if (versionNumber != null) this.synapsePlaceToken += "." + versionNumber;
    if (area != null) {
      this.synapsePlaceToken += getDelimiter(area);
      if (areaToken != null) {
        this.synapsePlaceToken += areaToken;
      }
    }
  }

  public String toToken() {
    return synapsePlaceToken;
  }

  public String getEntityId() {
    return entityId;
  }

  public Long getVersionNumber() {
    return versionNumber;
  }

  public Synapse.EntityArea getArea() {
    return area;
  }

  public String getAreaToken() {
    return areaToken;
  }

  public void setArea(Synapse.EntityArea area) {
    this.area = area;
    calculateToken(entityId, versionNumber, area, areaToken);
  }

  public void setAreaToken(String areaToken) {
    this.areaToken = areaToken;
    calculateToken(entityId, versionNumber, area, areaToken);
  }

  @Prefix("!Synapse")
  public static class Tokenizer implements PlaceTokenizer<Synapse> {

    @Override
    public String getToken(Synapse place) {
      return place.toToken();
    }

    @Override
    public Synapse getPlace(String token) {
      return new Synapse(token);
    }
  }

  public static enum EntityArea {
    WIKI,
    FILES,
    DATASETS,
    TABLES,
    CHALLENGE,
    DISCUSSION,
    DOCKER,
  }

  public static enum ProfileArea {
    PROFILE,
    FAVORITES,
    PROJECTS,
    CHALLENGES,
    TEAMS,
    SETTINGS,
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result =
      prime *
      result +
      ((synapsePlaceToken == null) ? 0 : synapsePlaceToken.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;
    if (getClass() != obj.getClass()) return false;
    Synapse other = (Synapse) obj;
    if (synapsePlaceToken == null) {
      if (other.synapsePlaceToken != null) return false;
    } else if (!synapsePlaceToken.equals(other.synapsePlaceToken)) return false;
    return true;
  }

  /**
   * Given a string where the version number is delimited with a dot (.) convert to a valid token.
   *
   * @param dotNotation
   * @return
   */
  public static String getHrefForDotVersion(String dotNotation) {
    dotNotation = StringUtils.emptyAsNull(dotNotation);
    if (dotNotation == null) {
      return null;
    }
    return SYNAPSE_ENTITY_PREFIX + dotNotation.toLowerCase();
  }
}

redpajama_set_name: RedPajamaGithub


text:
import sys

if sys.version_info[:2] >= (3, 8):
    # TODO: Import directly (no need for conditional) when `python_requires = >= 3.8`
    from importlib.metadata import PackageNotFoundError, version  # pragma: no cover
else:
    from importlib_metadata import PackageNotFoundError, version  # pragma: no cover

try:
    # Change here if project is renamed and does not equal the package name
    dist_name = "panoptes-pocs"
    __version__ = version(dist_name)
except PackageNotFoundError:  # pragma: no cover
    __version__ = "unknown"
finally:
    del version, PackageNotFoundError


text:
/*
Gradebook from Names and Scores
I worked on this challenge with Hana Worku
This challenge took me [#] hours.
You will work with the following two variables.  The first, students, holds the names of four students.
The second, scores, holds groups of test scores.  The relative positions of elements within the two
variables match (i.e., 'Joseph' is the first element in students; his scores are the first value in scores.).
Do not alter the students and scores code.
*/

// __________________________________________
// Write your code below.

// var students = ["Joseph", "Susan", "William", "Elizabeth"];

// var scores = [ [80, 70, 70, 100],
//                [85, 80, 90, 90],
//                [75, 70, 80, 75],
//                [100, 90, 95, 85] ];

// var gradebook = {};

// gradebook.addScore = function(name, score){
//   gradebook[name].testScores.push(score);
// };

// gradebook.getAverage = function(name){
//   return gradebook.average(gradebook[name].testScores);
// };

// function average(array){
//   var sum = 0;
//   for (var i = 0; i < array.length; i++) {
//     sum += array[i];
//   }
//   return sum/array.length;
// }

// gradebook.average = average;

// for(i=0; i < students.length ; i++){
//   gradebook[students[i]] = {};
//   gradebook[students[i]].testScores = scores[i];
// }

// console.log(gradebook.average(gradebook["Joseph"].testScores));
// console.log(gradebook.getAverage("Joseph"));

// __________________________________________
// Refactored Solution

var students = ["Joseph", "Susan", "William", "Elizabeth"];

var scores = [ [80, 70, 70, 100],
               [85, 80, 90, 90],
               [75, 70, 80, 75],
               [100, 90, 95, 85] ];

var gradebook = {};

gradebook.addScore = function(name, score){
  gradebook[name].testScores.push(score);
};

gradebook.getAverage = function(name){
  return gradebook.average(gradebook[name].testScores);
};

function average(array){
  var sum = array.reduce(function(a, b) {
    return a + b;
  });
  return sum/array.length;
}

gradebook.average = average;

for(i=0; i < students.length ; i++){
  gradebook[students[i]] = {testScores: scores[i]};
}

console.log(gradebook.average(gradebook["Joseph"].testScores));
console.log(gradebook.getAverage("Joseph"));

// __________________________________________
// Reflect
// What did you learn about adding functions to objects?
/*   I learned that
objects don't recognize an anonymous function as a function type when
assigned to a variable property. For an object's property to be
considered a function the function must be declared and named above
the assignment and then explicitly assigned to the function property.

// How did you iterate over nested arrays in JavaScript?

  We used bracket notation and a for loop. Its basically ecactly that
  same as in ruby. We passed in a variable to the bracket that held
  the current index to retrieved, and used the for loop to increment
  the pointer and iterate through each element.

// Were there any new methods you were able to incorporate? If so,
// what were they and how did they work?

  We used the reduce in our refactored solution to sum all of the
  elements in an array. To use reduce you pass in a function, The
  function supplied may have up to 4 arguments. The first argument
  would be the previous value, which is what was returned from the
  last invocation of the function, the current value, which is the
  current element being processed in the array, the current index, and
  the array reduce was called on. these argument are optional, but to
  use them properly, they must be supplied the proper order. We only
  used previous value and current value and named them a and b. we
  just repeatedly added b to a as summed all of the elements.

*/

// __________________________________________
// Test Code:  Do not alter code below this line.

function assert(test, message, test_number) {
  if (!test) {
    console.log(test_number + "false");
    throw "ERROR: " + message;
  }
  console.log(test_number + "true");
  return true;
}

assert(
  (gradebook instanceof Object),
  "The value of gradebook should be an Object.\n",
  "1. "
)

assert(
  (gradebook["Elizabeth"] instanceof Object),
  "gradebook's Elizabeth property should be an object.",
  "2. "
)

assert(
  (gradebook.William.testScores === scores[2]),
  "William's testScores should equal the third element in scores.",
  "3. "
)

assert(
  (gradebook.addScore instanceof Function),
  "The value of gradebook's addScore property should be a Function.",
  "4. "
)

gradebook.addScore("Susan", 80)

assert(
  (gradebook.Susan.testScores.length === 5
   && gradebook.Susan.testScores[4] === 80),
  "Susan's testScores should have a new score of 80 added to the end.",
  "5. "
)

assert(
  (gradebook.getAverage instanceof Function),
  "The value of gradebook's getAverage property should be a Function.",
  "6. "
)

assert(
  (average instanceof Function),
  "The value of average should be a Function.\n",
  "7. "
)
assert(
  average([1, 2, 3]) === 2,
  "average should return the average of the elements in the array argument.\n",
  "8. "
)

assert(
  (gradebook.getAverage("Joseph") === 80),
  "gradebook's getAverage should return 80 if passed 'Joseph'.",
  "9. "
)


text:
#include <Array.hpp>

namespace opencl {
template<typename T>
Array<uint> where(const Array<T>& in);
}


text:
import React from 'react'
import PropTypes from 'prop-types'
import FirebaseApp from '../firebaseapp'

import { getCompLevelStr, getMatchSetStr } from '../helpers'

import CurrentMatchDisplay from './CurrentMatchDisplay'
import LastMatchesTable from './LastMatchesTable'
import UpcomingMatchesTable from './UpcomingMatchesTable'

const compLevelsPlayOrder = {
  qm: 1,
  ef: 2,
  qf: 3,
  sf: 4,
  f: 5,
}

function playOrder(match) {
  return (compLevelsPlayOrder[match.c] * 100000) + (match.m * 100) + match.s
}

class LiveEventPanel extends React.PureComponent {
  state = {
    playedMatches: null,
    unplayedMatches: null,
    matchState: null,
    currentTime: undefined,
  }

  componentDidMount() {
    this.updateCurrentTime()
    setInterval(this.updateCurrentTime, 10000)

    FirebaseApp.database().ref(`/e/${this.props.eventKey}/m`).on('value', (snapshot) => {
      const val = snapshot.val()
      const matches = []
      if (val) {
        Object.keys(val).forEach((shortKey) => {
          const match = val[shortKey]
          match.key = `${this.props.eventKey}_${shortKey}`
          match.shortKey = shortKey
          matches.push(match)
        })
      }
      matches.sort((match1, match2) => playOrder(match1) - playOrder(match2))

      const playedMatches = matches.filter((match) => match.r !== -1 && match.b !== -1)
      // Compute next unplayed matches, skipping unplayed matches in the middle of played ones
      let unplayedMatches = []
      matches.forEach((match) => {
        if (match.r !== -1 && match.b !== -1) {
          unplayedMatches = []
        } else {
          unplayedMatches.push(match)
        }
      })
      this.setState({
        playedMatches,
        unplayedMatches,
      })
    })
    FirebaseApp.database().ref(`/le/${this.props.eventKey}`).on('value', (snapshot) => {
      this.setState({
        matchState: snapshot.val(),
      })
    })
  }

  updateCurrentTime = () => {
    this.setState({ currentTime: new Date().getTime() / 1000 })
  }

  render() {
    const { playedMatches, unplayedMatches, matchState } = this.state

    const playedMatchesCopy = playedMatches && playedMatches.slice()
    const unplayedMatchesCopy = unplayedMatches && unplayedMatches.slice()

    let upcomingMatches = null
    let currentMatch = null
    let forcePreMatch = false
    if (unplayedMatchesCopy !== null) {
      if (matchState === null || matchState.mk.startsWith('pm')) {
        upcomingMatches = unplayedMatchesCopy.slice(0, 3)
      } else {
        playedMatchesCopy.forEach((match, i) => {
          if (match.shortKey === matchState.mk && matchState.m !== 'post_match') {
            currentMatch = playedMatchesCopy.splice(i, 1)[0]
          }
        })
        unplayedMatchesCopy.forEach((match, i) => {
          if (match.shortKey === matchState.mk) {
            currentMatch = unplayedMatchesCopy.splice(i, 1)[0]
          }
        })
        if (!currentMatch) { // Must have been in playedMatches, but mode is post_match
          currentMatch = unplayedMatchesCopy.splice(0, 1)[0]
          forcePreMatch = true
        }
        upcomingMatches = unplayedMatchesCopy.slice(0, 3)
      }
    }

    let etaStr = ''
    if (forcePreMatch && currentMatch) {
      if (this.state.currentTime && currentMatch.pt) {
        const etaMin = (currentMatch.pt - this.state.currentTime) / 60
        if (etaMin < 2) {
          etaStr = ' in <2 min'
        } else if (etaMin > 120) {
          etaStr = ` in ~${Math.round(etaMin / 60)} h`
        } else {
          etaStr = ` in ~${Math.round(etaMin)} min`
        }
      }
    }

    const year = parseInt(this.props.eventKey.substring(0, 4), 10)
    return (

        {!this.props.simple &&
        <div className={`${currentMatch ? 'col-lg-3' : 'col-lg-6'} text-center livePanelColumn`}>

Last Matches

          <LastMatchesTable year={year} matches={playedMatchesCopy && playedMatchesCopy.slice(-3)} />

        }
        {currentMatch &&
        <div className={`${this.props.simple ? '' : 'col-lg-6'} text-center livePanelColumn`}>
          {forcePreMatch ?

Next Match{etaStr}: {`${getCompLevelStr(currentMatch)} ${getMatchSetStr(currentMatch)}`}

            :

Current Match: {`${getCompLevelStr(currentMatch)} ${getMatchSetStr(currentMatch)}`}

          }
          <CurrentMatchDisplay year={year} match={currentMatch} matchState={matchState} forcePreMatch={forcePreMatch} />

        }
        {!this.props.simple &&
        <div className={`${currentMatch ? 'col-lg-3' : 'col-lg-6'} text-center livePanelColumn`}>

Upcoming Matches

          <UpcomingMatchesTable year={year} matches={upcomingMatches} />

        }

    )
  }
}

LiveEventPanel.propTypes = {
  eventKey: PropTypes.string.isRequired,
  simple: PropTypes.bool.isRequired,
}

export default LiveEventPanel


text:
using ServiceStack.ServiceInterface;

namespace ServiceStack.FluentValidation
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq.Expressions;
    using Internal;
    using Results;
    using Validators;

    /// <summary>
    /// Extension methods that provide the default set of validators.
    /// </summary>
    public static class DefaultValidatorExtensions {
        /// <summary>
        /// Defines a 'not null' validator on the current rule builder.
        /// Validation will fail if the property is null.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> NotNull<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder) {
            return ruleBuilder.SetValidator(new NotNullValidator());
        }

        /// <summary>
        /// Defines a 'not empty' validator on the current rule builder.
        /// Validation will fail if the property is null, an empty or the default value for the type (for example, 0 for integers)
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> NotEmpty<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder) {
            return ruleBuilder.SetValidator(new NotEmptyValidator(default(TProperty)));
        }

        /// <summary>
        /// Defines a length validator on the current rule builder, but only for string properties.
        /// Validation will fail if the length of the string is outside of the specifed range. The range is inclusive.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, string> Length<T>(this IRuleBuilder<T, string> ruleBuilder, int min, int max) {
            return ruleBuilder.SetValidator(new LengthValidator(min, max));
        }

        /// <summary>
        /// Defines a length validator on the current rule builder, but only for string properties.
        /// Validation will fail if the length of the string is not equal to the length specified.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, string> Length<T>(this IRuleBuilder<T, string> ruleBuilder, int exactLength) {
            return ruleBuilder.SetValidator(new ExactLengthValidator(exactLength));
        }

        /// <summary>
        /// Defines a regular expression validator on the current rule builder, but only for string properties.
        /// Validation will fail if the value returned by the lambda does not match the regular expression.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="expression">The regular expression to check the value against.</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, string> Matches<T>(this IRuleBuilder<T, string> ruleBuilder, string expression) {
            return ruleBuilder.SetValidator(new RegularExpressionValidator(expression));
        }

        /// <summary>
        /// Defines a regular expression validator on the current rule builder, but only for string properties.
        /// Validation will fail if the value returned by the lambda is not a valid email address.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, string> EmailAddress<T>(this IRuleBuilder<T, string> ruleBuilder) {
            return ruleBuilder.SetValidator(new EmailValidator());
        }

        /// <summary>
        /// Defines a 'not equal' validator on the current rule builder.
        /// Validation will fail if the specified value is equal to the value of the property.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="toCompare">The value to compare</param>
        /// <param name="comparer">Equality comparer to use</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> NotEqual<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder,
                                                                               TProperty toCompare, IEqualityComparer comparer = null) {
            return ruleBuilder.SetValidator(new NotEqualValidator(toCompare, comparer));
        }

        /// <summary>
        /// Defines a 'not equal' validator on the current rule builder using a lambda to specify the value.
        /// Validation will fail if the value returned by the lambda is equal to the value of the property.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="expression">A lambda expression to provide the comparison value</param>
        /// <param name="comparer">Equality Comparer to use</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> NotEqual<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder,
                                                                               Expression<Func<T, TProperty>> expression, IEqualityComparer comparer = null) {
            var func = expression.Compile();
            return ruleBuilder.SetValidator(new NotEqualValidator(func.CoerceToNonGeneric(), expression.GetMember(), comparer));
        }

        /// <summary>
        /// Defines an 'equals' validator on the current rule builder.
        /// Validation will fail if the specified value is not equal to the value of the property.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="toCompare">The value to compare</param>
        /// <param name="comparer">Equality Comparer to use</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> Equal<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder, TProperty toCompare, IEqualityComparer comparer = null) {
            return ruleBuilder.SetValidator(new EqualValidator(toCompare, comparer));
        }

        /// <summary>
        /// Defines an 'equals' validator on the current rule builder using a lambda to specify the comparison value.
        /// Validation will fail if the value returned by the lambda is not equal to the value of the property.
        /// </summary>
        /// <typeparam name="T">The type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="expression">A lambda expression to provide the comparison value</param>
        /// <param name="comparer">Equality comparer to use</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> Equal<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder, Expression<Func<T, TProperty>> expression, IEqualityComparer comparer = null) {
            var func = expression.Compile();
            return ruleBuilder.SetValidator(new EqualValidator(func.CoerceToNonGeneric(), expression.GetMember(), comparer));
        }

        /// <summary>
        /// Defines a predicate validator on the current rule builder using a lambda expression to specify the predicate.
        /// Validation will fail if the specified lambda returns false.
        /// Validation will succeed if the specifed lambda returns true.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="predicate">A lambda expression specifying the predicate</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> Must<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder,
                                                                           Func<TProperty, bool> predicate) {
            predicate.Guard("Cannot pass a null predicate to Must.");

            return ruleBuilder.Must((x, val) => predicate(val));
        }

        /// <summary>
        /// Defines a predicate validator on the current rule builder using a lambda expression to specify the predicate.
        /// Validation will fail if the specified lambda returns false.
        /// Validation will succeed if the specifed lambda returns true.
        /// This overload accepts the object being validated in addition to the property being validated.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="predicate">A lambda expression specifying the predicate</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> Must<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder,
                                                                           Func<T, TProperty, bool> predicate) {
            predicate.Guard("Cannot pass a null predicate to Must.");
            return ruleBuilder.Must((x, val, propertyValidatorContext) => predicate(x, val));
        }

        /// <summary>
        /// Defines a predicate validator on the current rule builder using a lambda expression to specify the predicate.
        /// Validation will fail if the specified lambda returns false.
        /// Validation will succeed if the specifed lambda returns true.
        /// This overload accepts the object being validated in addition to the property being validated.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="predicate">A lambda expression specifying the predicate</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> Must<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder,
                                                                           Func<T, TProperty, PropertyValidatorContext, bool> predicate) {
            predicate.Guard("Cannot pass a null predicate to Must.");
            return ruleBuilder.SetValidator(new PredicateValidator((instance, property, propertyValidatorContext) => predicate((T)instance, (TProperty)property, propertyValidatorContext)));
        }

        /// <summary>
        /// Defines a 'less than' validator on the current rule builder.
        /// The validation will succeed if the property value is less than the specified value.
        /// The validation will fail if the property value is greater than or equal to the specified value.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="valueToCompare">The value being compared</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> LessThan<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder,
                                                                               TProperty valueToCompare)
            where TProperty : IComparable<TProperty>, IComparable {
            return ruleBuilder.SetValidator(new LessThanValidator(valueToCompare));
        }

        /// <summary>
        /// Defines a 'less than' validator on the current rule builder.
        /// The validation will succeed if the property value is less than the specified value.
        /// The validation will fail if the property value is greater than or equal to the specified value.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="valueToCompare">The value being compared</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, Nullable<TProperty>> LessThan<T, TProperty>(this IRuleBuilder<T, Nullable<TProperty>> ruleBuilder,
                                                                               TProperty valueToCompare)
            where TProperty : struct, IComparable<TProperty>, IComparable {
            return ruleBuilder.SetValidator(new LessThanValidator(valueToCompare));
        }

        /// <summary>
        /// Defines a 'less than or equal' validator on the current rule builder.
        /// The validation will succeed if the property value is less than or equal to the specified value.
        /// The validation will fail if the property value is greater than the specified value.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="valueToCompare">The value being compared</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> LessThanOrEqualTo<T, TProperty>(
            this IRuleBuilder<T, TProperty> ruleBuilder, TProperty valueToCompare) where TProperty : IComparable<TProperty>, IComparable {
            return ruleBuilder.SetValidator(new LessThanOrEqualValidator(valueToCompare));
        }

        /// <summary>
        /// Defines a 'less than or equal' validator on the current rule builder.
        /// The validation will succeed if the property value is less than or equal to the specified value.
        /// The validation will fail if the property value is greater than the specified value.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="valueToCompare">The value being compared</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, Nullable<TProperty>> LessThanOrEqualTo<T, TProperty>(
            this IRuleBuilder<T, Nullable<TProperty>> ruleBuilder, TProperty valueToCompare) where TProperty : struct, IComparable<TProperty>, IComparable {
            return ruleBuilder.SetValidator(new LessThanOrEqualValidator(valueToCompare));
        }

        /// <summary>
        /// Defines a 'greater than' validator on the current rule builder.
        /// The validation will succeed if the property value is greater than the specified value.
        /// The validation will fail if the property value is less than or equal to the specified value.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="valueToCompare">The value being compared</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> GreaterThan<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder, TProperty valueToCompare)
            where TProperty : IComparable<TProperty>, IComparable {
            return ruleBuilder.SetValidator(new GreaterThanValidator(valueToCompare));
        }

        /// <summary>
        /// Defines a 'greater than' validator on the current rule builder.
        /// The validation will succeed if the property value is greater than the specified value.
        /// The validation will fail if the property value is less than or equal to the specified value.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="valueToCompare">The value being compared</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, Nullable<TProperty>> GreaterThan<T, TProperty>(this IRuleBuilder<T, Nullable<TProperty>> ruleBuilder, TProperty valueToCompare)
            where TProperty : struct, IComparable<TProperty>, IComparable {
            return ruleBuilder.SetValidator(new GreaterThanValidator(valueToCompare));
        }

        /// <summary>
        /// Defines a 'greater than or equal' validator on the current rule builder.
        /// The validation will succeed if the property value is greater than or equal the specified value.
        /// The validation will fail if the property value is less than the specified value.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="valueToCompare">The value being compared</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> GreaterThanOrEqualTo<T, TProperty>(
            this IRuleBuilder<T, TProperty> ruleBuilder, TProperty valueToCompare) where TProperty : IComparable<TProperty>, IComparable {
            return ruleBuilder.SetValidator(new GreaterThanOrEqualValidator(valueToCompare));
        }

        /// <summary>
        /// Defines a 'greater than or equal' validator on the current rule builder.
        /// The validation will succeed if the property value is greater than or equal the specified value.
        /// The validation will fail if the property value is less than the specified value.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="valueToCompare">The value being compared</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, Nullable<TProperty>> GreaterThanOrEqualTo<T, TProperty>(
            this IRuleBuilder<T, Nullable<TProperty>> ruleBuilder, TProperty valueToCompare) where TProperty : struct, IComparable<TProperty>, IComparable {
            return ruleBuilder.SetValidator(new GreaterThanOrEqualValidator(valueToCompare));
        }

        /// <summary>
        /// Defines a 'less than' validator on the current rule builder using a lambda expression.
        /// The validation will succeed if the property value is less than the specified value.
        /// The validation will fail if the property value is greater than or equal to the specified value.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="expression">A lambda that should return the value being compared</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> LessThan<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder,
                                                                               Expression<Func<T, TProperty>> expression)
            where TProperty : IComparable<TProperty>, IComparable {
            expression.Guard("Cannot pass null to LessThan");

            var func = expression.Compile();

            return ruleBuilder.SetValidator(new LessThanValidator(func.CoerceToNonGeneric(), expression.GetMember()));
        }

        /// <summary>
        /// Defines a 'less than' validator on the current rule builder using a lambda expression.
        /// The validation will succeed if the property value is less than the specified value.
        /// The validation will fail if the property value is greater than or equal to the specified value.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="expression">A lambda that should return the value being compared</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, Nullable<TProperty>> LessThan<T, TProperty>(this IRuleBuilder<T, Nullable<TProperty>> ruleBuilder,
                                                                                Expression<Func<T, TProperty>> expression)
            where TProperty : struct, IComparable<TProperty>, IComparable {
            expression.Guard("Cannot pass null to LessThan");

            var func = expression.Compile();

            return ruleBuilder.SetValidator(new LessThanValidator(func.CoerceToNonGeneric(), expression.GetMember()));
        }

        /// <summary>
        /// Defines a 'less than or equal' validator on the current rule builder using a lambda expression.
        /// The validation will succeed if the property value is less than or equal to the specified value.
        /// The validation will fail if the property value is greater than the specified value.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="expression">The value being compared</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> LessThanOrEqualTo<T, TProperty>(
            this IRuleBuilder<T, TProperty> ruleBuilder, Expression<Func<T, TProperty>> expression)
            where TProperty : IComparable<TProperty>, IComparable {
            var func = expression.Compile();

            return ruleBuilder.SetValidator(new LessThanOrEqualValidator(func.CoerceToNonGeneric(), expression.GetMember()));
        }

        /// <summary>
        /// Defines a 'less than or equal' validator on the current rule builder using a lambda expression.
        /// The validation will succeed if the property value is less than or equal to the specified value.
        /// The validation will fail if the property value is greater than the specified value.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="expression">The value being compared</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, Nullable<TProperty>> LessThanOrEqualTo<T, TProperty>(
            this IRuleBuilder<T, Nullable<TProperty>> ruleBuilder, Expression<Func<T, TProperty>> expression)
            where TProperty : struct, IComparable<TProperty>, IComparable
        {
            var func = expression.Compile();

            return ruleBuilder.SetValidator(new LessThanOrEqualValidator(func.CoerceToNonGeneric(), expression.GetMember()));
        }

        /// <summary>
        /// Defines a 'less than' validator on the current rule builder using a lambda expression.
        /// The validation will succeed if the property value is greater than the specified value.
        /// The validation will fail if the property value is less than or equal to the specified value.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="expression">The value being compared</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> GreaterThan<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder,
                                                                                Expression<Func<T, TProperty>> expression)
            where TProperty : IComparable<TProperty>, IComparable {
            var func = expression.Compile();

            return ruleBuilder.SetValidator(new GreaterThanValidator(func.CoerceToNonGeneric(), expression.GetMember()));
        }

        /// <summary>
        /// Defines a 'less than' validator on the current rule builder using a lambda expression.
        /// The validation will succeed if the property value is greater than the specified value.
        /// The validation will fail if the property value is less than or equal to the specified value.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="expression">The value being compared</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, Nullable<TProperty>> GreaterThan<T, TProperty>(this IRuleBuilder<T, Nullable<TProperty>> ruleBuilder,
                                                                                Expression<Func<T, TProperty>> expression)
            where TProperty : struct, IComparable<TProperty>, IComparable
        {
            var func = expression.Compile();

            return ruleBuilder.SetValidator(new GreaterThanValidator(func.CoerceToNonGeneric(), expression.GetMember()));
        }

        /// <summary>
        /// Defines a 'less than' validator on the current rule builder using a lambda expression.
        /// The validation will succeed if the property value is greater than or equal the specified value.
        /// The validation will fail if the property value is less than the specified value.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="valueToCompare">The value being compared</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> GreaterThanOrEqualTo<T, TProperty>(
            this IRuleBuilder<T, TProperty> ruleBuilder, Expression<Func<T, TProperty>> valueToCompare)
            where TProperty : IComparable<TProperty>, IComparable {
            var func = valueToCompare.Compile();

            return ruleBuilder.SetValidator(new GreaterThanOrEqualValidator(func.CoerceToNonGeneric(), valueToCompare.GetMember()));
        }

        /// <summary>
        /// Defines a 'less than' validator on the current rule builder using a lambda expression.
        /// The validation will succeed if the property value is greater than or equal the specified value.
        /// The validation will fail if the property value is less than the specified value.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="valueToCompare">The value being compared</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, Nullable<TProperty>> GreaterThanOrEqualTo<T, TProperty>(
            this IRuleBuilder<T, Nullable<TProperty>> ruleBuilder, Expression<Func<T, TProperty>> valueToCompare)
            where TProperty : struct, IComparable<TProperty>, IComparable
        {
            var func = valueToCompare.Compile();

            return ruleBuilder.SetValidator(new GreaterThanOrEqualValidator(func.CoerceToNonGeneric(), valueToCompare.GetMember()));
        }

        /// <summary>
        /// Validates certain properties of the specified instance.
        /// </summary>
        /// <param name="validator">The current validator</param>
        /// <param name="instance">The object to validate</param>
        /// <param name="propertyExpressions">Expressions to specify the properties to validate</param>
        /// <returns>A ValidationResult object containing any validation failures</returns>
        public static ValidationResult Validate<T>(this IValidator<T> validator, T instance, params Expression<Func<T, object>>[] propertyExpressions) {
            var context = new ValidationContext<T>(instance, new PropertyChain(), MemberNameValidatorSelector.FromExpressions(propertyExpressions));
            return validator.Validate(context);
        }

        /// <summary>
        /// Validates certain properties of the specified instance.
        /// </summary>
        /// <param name="instance">The object to validate</param>
        /// <param name="properties">The names of the properties to validate.</param>
        /// <returns>A ValidationResult object containing any validation failures.</returns>
        public static ValidationResult Validate<T>(this IValidator<T> validator, T instance, params string[] properties) {
            var context = new ValidationContext<T>(instance, new PropertyChain(), new MemberNameValidatorSelector(properties));
            return validator.Validate(context);
        }

        public static ValidationResult Validate<T>(this IValidator<T> validator, T instance, IValidatorSelector selector = null, string ruleSet = null) {
            if(selector != null && ruleSet != null) {
                throw new InvalidOperationException("Cannot specify both an IValidatorSelector and a RuleSet.");
            }

            if(selector == null) {
                selector = new DefaultValidatorSelector();
            }

            if(ruleSet != null) {
                selector = new RulesetValidatorSelector(ruleSet);
            }

            var context = new ValidationContext<T>(instance, new PropertyChain(), selector);
            return validator.Validate(context);
        }

        /// <summary>
        /// Performs validation and then throws an exception if validation fails.
        /// </summary>
        public static void ValidateAndThrow<T>(this IValidator<T> validator, T instance) {
            var result = validator.Validate(instance);

            if(! result.IsValid) {
                throw new ValidationException(result.Errors);
            }
        }

        public static void ValidateAndThrow<T>(this IValidator<T> validator, T instance, ApplyTo ruleSet)
        {
            validator.ValidateAndThrow(instance, ruleSet.ToString().ToUpper());
        }

        public static void ValidateAndThrow<T>(this IValidator<T> validator, T instance, string ruleSet)
        {
            var result = validator.Validate(instance, (IValidatorSelector)null, ruleSet);

            if (!result.IsValid)
            {
                throw new ValidationException(result.Errors);
            }
        }

        /// <summary>
        /// Defines an 'inclusive between' validator on the current rule builder, but only for properties of types that implement IComparable.
        /// Validation will fail if the value of the property is outside of the specifed range. The range is inclusive.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="from">The lowest allowed value</param>
        /// <param name="to">The highest allowed value</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> InclusiveBetween<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder, TProperty from, TProperty to) where TProperty : IComparable<TProperty>, IComparable {
            return ruleBuilder.SetValidator(new InclusiveBetweenValidator(from, to));
        }

        /// <summary>
        /// Defines an 'inclusive between' validator on the current rule builder, but only for properties of types that implement IComparable.
        /// Validation will fail if the value of the property is outside of the specifed range. The range is inclusive.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="from">The lowest allowed value</param>
        /// <param name="to">The highest allowed value</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, Nullable<TProperty>> InclusiveBetween<T, TProperty>(this IRuleBuilder<T, Nullable<TProperty>> ruleBuilder, TProperty from, TProperty to) where TProperty : struct, IComparable<TProperty>, IComparable {
            return ruleBuilder.SetValidator(new InclusiveBetweenValidator(from, to));
        }

        /// <summary>
        /// Defines an 'exclusive between' validator on the current rule builder, but only for properties of types that implement IComparable.
        /// Validation will fail if the value of the property is outside of the specifed range. The range is exclusive.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="from">The lowest allowed value</param>
        /// <param name="to">The highest allowed value</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, TProperty> ExclusiveBetween<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder, TProperty from, TProperty to) where TProperty : IComparable<TProperty>, IComparable {
            return ruleBuilder.SetValidator(new ExclusiveBetweenValidator(from, to));
        }

        /// <summary>
        /// Defines an 'exclusive between' validator on the current rule builder, but only for properties of types that implement IComparable.
        /// Validation will fail if the value of the property is outside of the specifed range. The range is exclusive.
        /// </summary>
        /// <typeparam name="T">Type of object being validated</typeparam>
        /// <typeparam name="TProperty">Type of property being validated</typeparam>
        /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param>
        /// <param name="from">The lowest allowed value</param>
        /// <param name="to">The highest allowed value</param>
        /// <returns></returns>
        public static IRuleBuilderOptions<T, Nullable<TProperty>> ExclusiveBetween<T, TProperty>(this IRuleBuilder<T, Nullable<TProperty>> ruleBuilder, TProperty from, TProperty to) where TProperty : struct, IComparable<TProperty>, IComparable {
            return ruleBuilder.SetValidator(new ExclusiveBetweenValidator(from, to));
        }

        /// <summary>
        /// Defines a credit card validator for the current rule builder that ensures that the specified string is a valid credit card number.
        /// </summary>
        public static IRuleBuilderOptions<T,string> CreditCard<T>(this IRuleBuilder<T, string> ruleBuilder) {
            return ruleBuilder.SetValidator(new CreditCardValidator());
        }
    }
}


text:
/*
  WARNING: THIS FILE IS AUTO-GENERATED. DO NOT MODIFY.

  This file was generated from .idl using "rtiddsgen".
  The rtiddsgen tool is part of the RTI Connext distribution.
  For more information, type 'rtiddsgen -help' at a command shell
  or consult the RTI Connext manual.
*/

import com.rti.dds.infrastructure.*;
import com.rti.dds.infrastructure.Copyable;

import java.io.Serializable;
import com.rti.dds.cdr.CdrHelper;

public class LittleMsg implements Copyable, Serializable
{

    public int messagenumber = 0;
    public String sender = ""; /* maximum length = ((MSG_LEN.VALUE)) */
    public String message = ""; /* maximum length = ((MSG_LEN.VALUE)) */

    public LittleMsg() {

    }

    public LittleMsg(LittleMsg other) {

        this();
        copy_from(other);
    }

    public static Object create() {
        LittleMsg self;
        self = new LittleMsg();

        self.clear();

        return self;
    }

    public void clear() {

        messagenumber = 0;

        sender = "";

        message = "";

    }

    public boolean equals(Object o) {

        if (o == null) {
            return false;
        }

        if(getClass() != o.getClass()) {
            return false;
        }

        LittleMsg otherObj = (LittleMsg)o;

        if(messagenumber != otherObj.messagenumber) {
            return false;
        }

        if(!sender.equals(otherObj.sender)) {
            return false;
        }

        if(!message.equals(otherObj.message)) {
            return false;
        }

        return true;
    }

    public int hashCode() {
        int __result = 0;

        __result += (int)messagenumber;

        __result += sender.hashCode();

        __result += message.hashCode();

        return __result;
    }

    /**
     * This is the implementation of the Copyable interface.
     * This method will perform a deep copy of src
     * This method could be placed into LittleMsgTypeSupport
     * rather than here by using the -noCopyable option
     * to rtiddsgen.
     *
     * @param src The Object which contains the data to be copied.
     * @return Returns this.
     * @exception NullPointerException If src is null.
     * @exception ClassCastException If src is not the
     * same type as this.
     * @see com.rti.dds.infrastructure.Copyable#copy_from(java.lang.Object)
     */
    public Object copy_from(Object src) {

        LittleMsg typedSrc = (LittleMsg) src;
        LittleMsg typedDst = this;

        typedDst.messagenumber = typedSrc.messagenumber;

        typedDst.sender = typedSrc.sender;

        typedDst.message = typedSrc.message;

        return this;
    }

    public String toString(){
        return toString("", 0);
    }

    public String toString(String desc, int indent) {
        StringBuffer strBuffer = new StringBuffer();

        if (desc != null) {
            CdrHelper.printIndent(strBuffer, indent);
            strBuffer.append(desc).append(":\n");
        }

        CdrHelper.printIndent(strBuffer, indent+1);
        strBuffer.append("messagenumber: ").append(messagenumber).append("\n");

        CdrHelper.printIndent(strBuffer, indent+1);
        strBuffer.append("sender: ").append(sender).append("\n");

        CdrHelper.printIndent(strBuffer, indent+1);
        strBuffer.append("message: ").append(message).append("\n");

        return strBuffer.toString();
    }

}