<commit_before>#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require File.dirname(__FILE__) + '/../test_helper'
require File.dirname(__FILE__) + '/test_helper'
require 'sass/engine'
require 'stringio'
require 'mock_importer'
require 'pathname'

module Sass::Script::Functions::UserFunctions
  def option(name)
    Sass::Script::String.new(@options[name.value.to_sym].to_s)
  end
end

class SassEngineTest < Test::Unit::TestCase
  FAKE_FILE_NAME = __FILE__.gsub(/rb$/,"sass")
  # A map of erroneous Sass documents to the error messages they should produce.
  # The error messages may be arrays;
  # if so, the second element should be the line number that should be reported for the error.
  # If this isn't provided, the tests will assume the line number should be the last line of the document.
  EXCEPTION_MAP = {
    "$a: 1 + " => 'Invalid CSS after "1 +": expected expression (e.g. 1px, bold), was ""',
    "$a: 1 + 2 +" => 'Invalid CSS after "1 + 2 +": expected expression (e.g. 1px, bold), was ""',
    "$a: 1 + 2 + %" => 'Invalid CSS after "1 + 2 + ": expected expression (e.g. 1px, bold), was "%"',
    "$a: foo(\"bar\"" => 'Invalid CSS after "foo("bar"": expected ")", was ""',
    "$a: 1 }" => 'Invalid CSS after "1 ": expected expression (e.g. 1px, bold), was "}"',
    "$a: 1 }foo\"" => 'Invalid CSS after "1 ": expected expression (e.g. 1px, bold), was "}foo""',
    ":" => 'Invalid property: ":".',
    ": a" => 'Invalid property: ": a".',
    "a\n  :b" => <<MSG,
Invalid property: ":b" (no value).
If ":b" should be a selector, use "\\:b" instead.
MSG
    "a\n  b:" => 'Invalid property: "b:" (no value).',
    "a\n  :b: c" => 'Invalid property: ":b: c".',
    "a\n  :b:c d" => 'Invalid property: ":b:c d".',
    "a\n  :b c;" => 'Invalid CSS after "c": expected expression (e.g. 1px, bold), was ";"',
    "a\n  b: c;" => 'Invalid CSS after "c": expected expression (e.g. 1px, bold), was ";"',
    ".foo ^bar\n  a: b" => ['Invalid CSS after ".foo ": expected selector, was "^bar"', 1],
    "a\n  @extend .foo ^bar" => 'Invalid CSS after ".foo ": expected selector, was "^bar"',
    "a\n  @extend .foo .bar" => "Can't extend .foo .bar: can't extend nested selectors",
    "a\n  @extend >" => "Can't extend >: invalid selector",
    "a\n  @extend &.foo" => "Can't extend &.foo: can't extend parent selectors",
    "a: b" => 'Properties are only allowed within rules, directives, mixin includes, or other properties.',
    ":a b" => 'Properties are only allowed within rules, directives, mixin includes, or other properties.',
    "$" => 'Invalid variable: "$".',
    "$a" => 'Invalid variable: "$a".',
    "$ a" => 'Invalid variable: "$ a".',
    "$a b" => 'Invalid variable: "$a b".',
    "$a: 1b + 2c" => "Incompatible units: 'c' and 'b'.",
    "$a: 1b < 2c" => "Incompatible units: 'c' and 'b'.",
    "$a: 1b > 2c" => "Incompatible units: 'c' and 'b'.",
    "$a: 1b <= 2c" => "Incompatible units: 'c' and 'b'.",
    "$a: 1b >= 2c" => "Incompatible units: 'c' and 'b'.",
    "a\n  b: 1b * 2c" => "2b*c isn't a valid CSS value.",
    "a\n  b: 1b % 2c" => "Cannot modulo by a number with units: 2c.",
    "$a: 2px + #ccc" => "Cannot add a number with units (2px) to a color (#cccccc).",
    "$a: #ccc + 2px" => "Cannot add a number with units (2px) to a color (#cccccc).",
    "& a\n  :b c" => ["Base-level rules cannot contain the parent-selector-referencing character '&'.", 1],
    "a\n  :b\n    c" => "Illegal nesting: Only properties may be nested beneath properties.",
    "$a: b\n  :c d\n" => "Illegal nesting: Nothing may be nested beneath variable declarations.",
    "$a: b\n  :c d\n" => "Illegal nesting: Nothing may be nested beneath variable declarations.",
    "@import templates/basic\n  foo" => "Illegal nesting: Nothing may be nested beneath import directives.",
    "foo\n  @import foo.css" => "CSS import directives may only be used at the root of a document.",
    "@if true\n  @import foo" => "Import directives may not be used within control directives or mixins.",
    "@mixin foo\n  @import foo" => "Import directives may not be used within control directives or mixins.",
    "@import foo;" => "Invalid @import: expected end of line, was \";\".",
    '$foo: "bar" "baz" !' => %Q{Invalid CSS after ""bar" "baz" ": expected expression (e.g. 1px, bold), was "!"},
    '$foo: "bar" "baz" $' => %Q{Invalid CSS after ""bar" "baz" ": expected expression (e.g. 1px, bold), was "$"}, #'
    "=foo\n  :color red\n.bar\n  +bang" => "Undefined mixin 'bang'.",
    "=foo\n  :color red\n.bar\n  +bang_bop" => "Undefined mixin 'bang_bop'.",
    "=foo\n  :color red\n.bar\n  +bang-bop" => "Undefined mixin 'bang-bop'.",
    ".bar\n  =foo\n    :color red\n" => ["Mixins may only be defined at the root of a document.", 2],
    "    a\n  b: c" => ["Indenting at the beginning of the document is illegal.", 1],
    " \n   \n\t\n  a\n  b: c" => ["Indenting at the beginning of the document is illegal.", 4],
    "a\n  b: c\n b: c" => ["Inconsistent indentation: 1 space was used for indentation, but the rest of the document was indented using 2 spaces.", 3],
    "a\n  b: c\na\n b: c" => ["Inconsistent indentation: 1 space was used for indentation, but the rest of the document was indented using 2 spaces.", 4],
    "a\n\t\tb: c\n\tb: c" => ["Inconsistent indentation: 1 tab was used for indentation, but the rest of the document was indented using 2 tabs.", 3],
    "a\n  b: c\n   b: c" => ["Inconsistent indentation: 3 spaces were used for indentation, but the rest of the document was indented using 2 spaces.", 3],
    "a\n  b: c\n  a\n   d: e" => ["Inconsistent indentation: 3 spaces were used for indentation, but the rest of the document was indented using 2 spaces.", 4],
    "a\n  b: c\na\n    d: e" => ["The line was indented 2 levels deeper than the previous line.", 4],
    "a\n  b: c\n  a\n        d: e" => ["The line was indented 3 levels deeper than the previous line.", 4],
    "a\n \tb: c" => ["Indentation can't use both tabs and spaces.", 2],
    "=a(" => 'Invalid CSS after "(": expected variable (e.g. $foo), was ""',
    "=a(b)" => 'Invalid CSS after "(": expected variable (e.g. $foo), was "b)"',
    "=a(,)" => 'Invalid CSS after "(": expected variable (e.g. $foo), was ",)"',
    "=a($)" => 'Invalid CSS after "(": expected variable (e.g. $foo), was "$)"',
    "=a($foo bar)" => 'Invalid CSS after "($foo ": expected ")", was "bar)"',
    "=foo\n  bar: baz\n+foo" => ["Properties are only allowed within rules, directives, mixin includes, or other properties.", 2],
    "a-\#{$b\n  c: d" => ['Invalid CSS after "a-#{$b": expected "}", was ""', 1],
    "=a($b: 1, $c)" => "Required argument $c must come before any optional arguments.",
    "=a($b: 1)\n  a: $b\ndiv\n  +a(1,2)" => "Mixin a takes 1 argument but 2 were passed.",
    "=a($b: 1)\n  a: $b\ndiv\n  +a(1,$c: 3)" => "Mixin a doesn't have an argument named $c",
    "=a($b)\n  a: $b\ndiv\n  +a" => "Mixin a is missing parameter $b.",
    "@function foo()\n  1 + 2" => "Functions can only contain variable declarations and control directives.",
    "@function foo()\n  foo: bar" => "Functions can only contain variable declarations and control directives.",
    "@function foo()\n  foo: bar\n  @return 3" => ["Functions can only contain variable declarations and control directives.", 2],
    "@function foo\n  @return 1" => ['Invalid CSS after "": expected "(", was ""', 1],
    "@function foo(\n  @return 1" => ['Invalid CSS after "(": expected variable (e.g. $foo), was ""', 1],
    "@function foo(b)\n  @return 1" => ['Invalid CSS after "(": expected variable (e.g. $foo), was "b)"', 1],
    "@function foo(,)\n  @return 1" => ['Invalid CSS after "(": expected variable (e.g. $foo), was ",)"', 1],
    "@function foo($)\n  @return 1" => ['Invalid CSS after "(": expected variable (e.g. $foo), was "$)"', 1],
    "@function foo()\n  @return" => 'Invalid @return: expected expression.',
    "@function foo()\n  @return 1\n    $var: val" => 'Illegal nesting: Nothing may be nested beneath return directives.',
    "foo\n  @function bar()\n    @return 1" => ['Functions may only be defined at the root of a document.', 2],
    "@function foo($a)\n  @return 1\na\n  b: foo()" => 'Function foo is missing parameter $a.',
    "@function foo()\n  @return 1\na\n  b: foo(2)" => 'Wrong number of arguments (1 for 0) for `foo\'',
    "@return 1" => '@return may only be used within a function.',
    "@if true\n  @return 1" => '@return may only be used within a function.',
    "@mixin foo\n  @return 1\n@include foo" => ['@return may only be used within a function.', 2],
    "@else\n  a\n    b: c" => ["@else must come after @if.", 1],
    "@if false\n@else foo" => "Invalid else directive '@else foo': expected 'if <expr>'.",
    "@if false\n@else if " => "Invalid else directive '@else if': expected 'if <expr>'.",
    "a\n  $b: 12\nc\n  d: $b" => 'Undefined variable: "$b".',
    "=foo\n  $b: 12\nc\n  +foo\n  d: $b" => 'Undefined variable: "$b".',
    "c\n  d: $b-foo" => 'Undefined variable: "$b-foo".',
    "c\n  d: $b_foo" => 'Undefined variable: "$b_foo".',
    '@for $a from "foo" to 1' => '"foo" is not an integer.',
    '@for $a from 1 to "2"' => '"2" is not an integer.',
    '@for $a from 1 to "foo"' => '"foo" is not an integer.',
    '@for $a from 1 to 1.232323' => '1.232 is not an integer.',
    '@for $a from 1px to 3em' => "Incompatible units: 'em' and 'px'.",
    '@if' => "Invalid if directive '@if': expected expression.",
    '@while' => "Invalid while directive '@while': expected expression.",
    '@debug' => "Invalid debug directive '@debug': expected expression.",
    %Q{@debug "a message"\n  "nested message"} => "Illegal nesting: Nothing may be nested beneath debug directives.",
    '@warn' => "Invalid warn directive '@warn': expected expression.",
    %Q{@warn "a message"\n  "nested message"} => "Illegal nesting: Nothing may be nested beneath warn directives.",
    "/* foo\n    bar\n  baz" => "Inconsistent indentation: previous line was indented by 4 spaces, but this line was indented by 2 spaces.",
    '+foo(1 + 1: 2)' => 'Invalid CSS after "(1 + 1": expected comma, was ": 2)"',
    '+foo($var: )' => 'Invalid CSS after "($var: ": expected mixin argument, was ")"',<commit_msg>Tests for unknown named args exceptions<commit_after>#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require File.dirname(__FILE__) + '/../test_helper'
require File.dirname(__FILE__) + '/test_helper'
require 'sass/engine'
require 'stringio'
require 'mock_importer'
require 'pathname'

module Sass::Script::Functions::UserFunctions
  def option(name)
    Sass::Script::String.new(@options[name.value.to_sym].to_s)
  end
end

class SassEngineTest < Test::Unit::TestCase
  FAKE_FILE_NAME = __FILE__.gsub(/rb$/,"sass")
  # A map of erroneous Sass documents to the error messages they should produce.
  # The error messages may be arrays;
  # if so, the second element should be the line number that should be reported for the error.
  # If this isn't provided, the tests will assume the line number should be the last line of the document.
  EXCEPTION_MAP = {
    "$a: 1 + " => 'Invalid CSS after "1 +": expected expression (e.g. 1px, bold), was ""',
    "$a: 1 + 2 +" => 'Invalid CSS after "1 + 2 +": expected expression (e.g. 1px, bold), was ""',
    "$a: 1 + 2 + %" => 'Invalid CSS after "1 + 2 + ": expected expression (e.g. 1px, bold), was "%"',
    "$a: foo(\"bar\"" => 'Invalid CSS after "foo("bar"": expected ")", was ""',
    "$a: 1 }" => 'Invalid CSS after "1 ": expected expression (e.g. 1px, bold), was "}"',
    "$a: 1 }foo\"" => 'Invalid CSS after "1 ": expected expression (e.g. 1px, bold), was "}foo""',
    ":" => 'Invalid property: ":".',
    ": a" => 'Invalid property: ": a".',
    "a\n  :b" => <<MSG,
Invalid property: ":b" (no value).
If ":b" should be a selector, use "\\:b" instead.
MSG
    "a\n  b:" => 'Invalid property: "b:" (no value).',
    "a\n  :b: c" => 'Invalid property: ":b: c".',
    "a\n  :b:c d" => 'Invalid property: ":b:c d".',
    "a\n  :b c;" => 'Invalid CSS after "c": expected expression (e.g. 1px, bold), was ";"',
    "a\n  b: c;" => 'Invalid CSS after "c": expected expression (e.g. 1px, bold), was ";"',
    ".foo ^bar\n  a: b" => ['Invalid CSS after ".foo ": expected selector, was "^bar"', 1],
    "a\n  @extend .foo ^bar" => 'Invalid CSS after ".foo ": expected selector, was "^bar"',
    "a\n  @extend .foo .bar" => "Can't extend .foo .bar: can't extend nested selectors",
    "a\n  @extend >" => "Can't extend >: invalid selector",
    "a\n  @extend &.foo" => "Can't extend &.foo: can't extend parent selectors",
    "a: b" => 'Properties are only allowed within rules, directives, mixin includes, or other properties.',
    ":a b" => 'Properties are only allowed within rules, directives, mixin includes, or other properties.',
    "$" => 'Invalid variable: "$".',
    "$a" => 'Invalid variable: "$a".',
    "$ a" => 'Invalid variable: "$ a".',
    "$a b" => 'Invalid variable: "$a b".',
    "$a: 1b + 2c" => "Incompatible units: 'c' and 'b'.",
    "$a: 1b < 2c" => "Incompatible units: 'c' and 'b'.",
    "$a: 1b > 2c" => "Incompatible units: 'c' and 'b'.",
    "$a: 1b <= 2c" => "Incompatible units: 'c' and 'b'.",
    "$a: 1b >= 2c" => "Incompatible units: 'c' and 'b'.",
    "a\n  b: 1b * 2c" => "2b*c isn't a valid CSS value.",
    "a\n  b: 1b % 2c" => "Cannot modulo by a number with units: 2c.",
    "$a: 2px + #ccc" => "Cannot add a number with units (2px) to a color (#cccccc).",
    "$a: #ccc + 2px" => "Cannot add a number with units (2px) to a color (#cccccc).",
    "& a\n  :b c" => ["Base-level rules cannot contain the parent-selector-referencing character '&'.", 1],
    "a\n  :b\n    c" => "Illegal nesting: Only properties may be nested beneath properties.",
    "$a: b\n  :c d\n" => "Illegal nesting: Nothing may be nested beneath variable declarations.",
    "$a: b\n  :c d\n" => "Illegal nesting: Nothing may be nested beneath variable declarations.",
    "@import templates/basic\n  foo" => "Illegal nesting: Nothing may be nested beneath import directives.",
    "foo\n  @import foo.css" => "CSS import directives may only be used at the root of a document.",
    "@if true\n  @import foo" => "Import directives may not be used within control directives or mixins.",
    "@mixin foo\n  @import foo" => "Import directives may not be used within control directives or mixins.",
    "@import foo;" => "Invalid @import: expected end of line, was \";\".",
    '$foo: "bar" "baz" !' => %Q{Invalid CSS after ""bar" "baz" ": expected expression (e.g. 1px, bold), was "!"},
    '$foo: "bar" "baz" $' => %Q{Invalid CSS after ""bar" "baz" ": expected expression (e.g. 1px, bold), was "$"}, #'
    "=foo\n  :color red\n.bar\n  +bang" => "Undefined mixin 'bang'.",
    "=foo\n  :color red\n.bar\n  +bang_bop" => "Undefined mixin 'bang_bop'.",
    "=foo\n  :color red\n.bar\n  +bang-bop" => "Undefined mixin 'bang-bop'.",
    ".bar\n  =foo\n    :color red\n" => ["Mixins may only be defined at the root of a document.", 2],
    "    a\n  b: c" => ["Indenting at the beginning of the document is illegal.", 1],
    " \n   \n\t\n  a\n  b: c" => ["Indenting at the beginning of the document is illegal.", 4],
    "a\n  b: c\n b: c" => ["Inconsistent indentation: 1 space was used for indentation, but the rest of the document was indented using 2 spaces.", 3],
    "a\n  b: c\na\n b: c" => ["Inconsistent indentation: 1 space was used for indentation, but the rest of the document was indented using 2 spaces.", 4],
    "a\n\t\tb: c\n\tb: c" => ["Inconsistent indentation: 1 tab was used for indentation, but the rest of the document was indented using 2 tabs.", 3],
    "a\n  b: c\n   b: c" => ["Inconsistent indentation: 3 spaces were used for indentation, but the rest of the document was indented using 2 spaces.", 3],
    "a\n  b: c\n  a\n   d: e" => ["Inconsistent indentation: 3 spaces were used for indentation, but the rest of the document was indented using 2 spaces.", 4],
    "a\n  b: c\na\n    d: e" => ["The line was indented 2 levels deeper than the previous line.", 4],
    "a\n  b: c\n  a\n        d: e" => ["The line was indented 3 levels deeper than the previous line.", 4],
    "a\n \tb: c" => ["Indentation can't use both tabs and spaces.", 2],
    "=a(" => 'Invalid CSS after "(": expected variable (e.g. $foo), was ""',
    "=a(b)" => 'Invalid CSS after "(": expected variable (e.g. $foo), was "b)"',
    "=a(,)" => 'Invalid CSS after "(": expected variable (e.g. $foo), was ",)"',
    "=a($)" => 'Invalid CSS after "(": expected variable (e.g. $foo), was "$)"',
    "=a($foo bar)" => 'Invalid CSS after "($foo ": expected ")", was "bar)"',
    "=foo\n  bar: baz\n+foo" => ["Properties are only allowed within rules, directives, mixin includes, or other properties.", 2],
    "a-\#{$b\n  c: d" => ['Invalid CSS after "a-#{$b": expected "}", was ""', 1],
    "=a($b: 1, $c)" => "Required argument $c must come before any optional arguments.",
    "=a($b: 1)\n  a: $b\ndiv\n  +a(1,2)" => "Mixin a takes 1 argument but 2 were passed.",
    "=a($b: 1)\n  a: $b\ndiv\n  +a(1,$c: 3)" => "Mixin a doesn't have an argument named $c",
    "=a($b)\n  a: $b\ndiv\n  +a" => "Mixin a is missing parameter $b.",
    "@function foo()\n  1 + 2" => "Functions can only contain variable declarations and control directives.",
    "@function foo()\n  foo: bar" => "Functions can only contain variable declarations and control directives.",
    "@function foo()\n  foo: bar\n  @return 3" => ["Functions can only contain variable declarations and control directives.", 2],
    "@function foo\n  @return 1" => ['Invalid CSS after "": expected "(", was ""', 1],
    "@function foo(\n  @return 1" => ['Invalid CSS after "(": expected variable (e.g. $foo), was ""', 1],
    "@function foo(b)\n  @return 1" => ['Invalid CSS after "(": expected variable (e.g. $foo), was "b)"', 1],
    "@function foo(,)\n  @return 1" => ['Invalid CSS after "(": expected variable (e.g. $foo), was ",)"', 1],
    "@function foo($)\n  @return 1" => ['Invalid CSS after "(": expected variable (e.g. $foo), was "$)"', 1],
    "@function foo()\n  @return" => 'Invalid @return: expected expression.',
    "@function foo()\n  @return 1\n    $var: val" => 'Illegal nesting: Nothing may be nested beneath return directives.',
    "foo\n  @function bar()\n    @return 1" => ['Functions may only be defined at the root of a document.', 2],
    "@function foo($a)\n  @return 1\na\n  b: foo()" => 'Function foo is missing parameter $a.',
    "@function foo()\n  @return 1\na\n  b: foo(2)" => 'Wrong number of arguments (1 for 0) for `foo\'',
    "@function foo()\n  @return 1\na\n  b: foo($a: 1)" => "Function foo doesn't have an argument: $a",
    "@function foo()\n  @return 1\na\n  b: foo($a: 1, $b: 2)" => "Function foo doesn't have an arguments: $a, $b",
    "@return 1" => '@return may only be used within a function.',
    "@if true\n  @return 1" => '@return may only be used within a function.',
    "@mixin foo\n  @return 1\n@include foo" => ['@return may only be used within a function.', 2],
    "@else\n  a\n    b: c" => ["@else must come after @if.", 1],
    "@if false\n@else foo" => "Invalid else directive '@else foo': expected 'if <expr>'.",
    "@if false\n@else if " => "Invalid else directive '@else if': expected 'if <expr>'.",
    "a\n  $b: 12\nc\n  d: $b" => 'Undefined variable: "$b".',
    "=foo\n  $b: 12\nc\n  +foo\n  d: $b" => 'Undefined variable: "$b".',
    "c\n  d: $b-foo" => 'Undefined variable: "$b-foo".',
    "c\n  d: $b_foo" => 'Undefined variable: "$b_foo".',
    '@for $a from "foo" to 1' => '"foo" is not an integer.',
    '@for $a from 1 to "2"' => '"2" is not an integer.',
    '@for $a from 1 to "foo"' => '"foo" is not an integer.',
    '@for $a from 1 to 1.232323' => '1.232 is not an integer.',
    '@for $a from 1px to 3em' => "Incompatible units: 'em' and 'px'.",
    '@if' => "Invalid if directive '@if': expected expression.",
    '@while' => "Invalid while directive '@while': expected expression.",
    '@debug' => "Invalid debug directive '@debug': expected expression.",
    %Q{@debug "a message"\n  "nested message"} => "Illegal nesting: Nothing may be nested beneath debug directives.",
    '@warn' => "Invalid warn directive '@warn': expected expression.",
    %Q{@warn "a message"\n  "nested message"} => "Illegal nesting: Nothing may be nested beneath warn directives.",
    "/* foo\n    bar\n  baz" => "Inconsistent indentation: previous line was indented by 4 spaces, but this line was indented by 2 spaces.",
    '+foo(1 + 1: 2)' => 'Invalid CSS after "(1 + 1": expected comma, was ": 2)"',
    '+foo($var: )' => 'Invalid CSS after "($var: ": expected mixin argument, was ")"',
{'fraction_non_alphanumeric': 0.19635255417956657, 'fraction_numerical': 0.01359326625386997, 'mean_word_length': 3.25633106856084, 'pattern_counts': {'":': 70, '<': 17, '<?xml version=': 0, '>': 231, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '3274782', 'n_tokens_mistral': 7357, 'n_tokens_neox': 7039, 'n_words': 2722}