<commit_before>describe("Rule", function(){
  describe("#$check", function(){
    it("when not ok", function(){
      var rule = valkyr.BaseRule.$retrieve("required");

      expect(
        rule.$check("username", undefined)
      ).toEqual({
        isOk: false,
        message: "The username field can't be empty."
      });
    });

    it("when ok", function(){
      var rule = valkyr.BaseRule.$retrieve("required");

      expect(
        rule.$check("username", "some user name")
      ).toEqual({
        isOk: true
      });
    });
  });

  describe("simple inheritance", function(){
    it("should have the same error when inheritance fails", function(){
      var negativeNumberRule = new window.valkyr.Rule({
        name: "negative",
        message: "The %s field must be a negative number.",
        inherits: "numeric",
        validator: function (value) {
          return value < 0;
        }
      });

      expect(
        negativeNumberRule.$check("value", "abc")
      ).toEqual({
        isOk: false,
        message: "The value field must be a negative number.",
      });
    });

    it("should display its own error message when the inheritance rule passes", function(){
      var negativeNumberRule = new window.valkyr.Rule({
        name: "negative",
        message: "The %s field must be a negative number.",
        inherits: "numeric",
        validator: function (value) {
          return value < 0;
        }
      });

      expect(
        negativeNumberRule.$check("value", 123)
      ).toEqual({
        isOk: false,
        message: "The value field must be a negative number."
      });<commit_msg>Adding credit card tests with inheritance<commit_after>describe("Rule", function(){
  describe("#$check", function(){
    it("when not ok", function(){
      var rule = valkyr.BaseRule.$retrieve("required");

      expect(
        rule.$check("username", undefined)
      ).toEqual({
        isOk: false,
        message: "The username field can't be empty."
      });
    });

    it("when ok", function(){
      var rule = valkyr.BaseRule.$retrieve("required");

      expect(
        rule.$check("username", "some user name")
      ).toEqual({
        isOk: true
      });
    });
  });

  describe("simple inheritance", function(){
    it("should have the same error when inheritance fails", function(){
      var negativeNumberRule = valkyr.Rule.build({
        name: "negative",
        message: "The %s field must be a negative number.",
        inherits: "numeric",
        validator: function (value) {
          return value < 0;
        }
      });

      expect(
        negativeNumberRule.$check("value", "abc")
      ).toEqual({
        isOk: false,
        message: "The value field must be a negative number.",
      });
    });

    it("should display its own error message when the inheritance rule passes", function(){
      var negativeNumberRule = valkyr.Rule.build({
        name: "negative",
        message: "The %s field must be a negative number.",
        inherits: "numeric",
        validator: function (value) {
          return value < 0;
        }
      });

      expect(
        negativeNumberRule.$check("value", 123)
      ).toEqual({
        isOk: false,
        message: "The value field must be a negative number."
      });
    });

    describe("credit cards", function() {

      describe("VISA", function() {
        it("with a non-valid VISA number", function() {
          var visaRule = valkyr.Rule.build({
            name: "VISA",
            message: "The %s field does not have a valid VISA credit-card number.",
            inherits: "credit-card",
            validator: function(number) {
              return !!number.match(/^4/);
            }
          });

          expect(
            visaRule.$check("CC", "5555555555554444")
          ).toEqual({
            isOk: false,
            message: "The CC field does not have a valid VISA credit-card number."
          });
        });

        it("with a valid VISA number", function() {
          var visaRule = valkyr.Rule.build({
            name: "VISA",
            message: "The %s field does not have a valid VISA credit-card number.",
            inherits: "credit-card",
            validator: function(number) {
              return !!number.match(/^4/);
            }
          });

          expect(
            visaRule.$check("CC", "4111111111111111")
          ).toEqual({
            isOk: true
          });
        });

      });
{'fraction_non_alphanumeric': 0.13625250055567903, 'fraction_numerical': 0.009779951100244499, 'mean_word_length': 1.9450261780104712, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4182480', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1191, 'n_words': 366}