# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.expand_path('../../../helper', __FILE__) class Reality::TestAttributes < Reality::TestCase def test_basic_operation_using_default_attributes content = < false }, attributes.attributes('README.md')) end def test_gitattributes_in_non_standard_location content = < false }, attributes.attributes('README.md')) assert_equal({ 'text' => false }, attributes.attributes('docs/README.md')) end def test_multi_value_attribute content = < true, 'crlf' => false, 'binary' => false }, attributes.attributes('README.textile')) assert_equal({ 'text' => true, 'crlf' => false, 'binary' => false }, attributes.attributes('doc/X.textile')) end def test_multi_patterns content = < false }, attributes.attributes('README.md')) assert_equal({ 'text' => true, 'crlf' => false, 'binary' => false }, attributes.attributes('doc/X.textile')) end def test_ignore_comments content = < true }, attributes.attributes('doc/X.md')) end def test_gitattributes_in_subdirectory content = < false }, attributes.attributes('foo/docs/README.md')) end def test_write_to content = < true) assert_equal(< '# DO NOT EDIT: File is auto-generated') assert_equal(< false) assert_equal(['* -text'], attributes.rules.collect {|p| p.to_s}) end def test_add_multiple_rules dir = "#{working_dir}/#{::SecureRandom.hex}" attributes = Reality::Git::Attributes.new(dir) assert_equal([], attributes.rules.collect {|p| p.to_s}) attributes.rule('*', :text => false) attributes.rule('*.so', :text => false) assert_equal(['* -text', '*.so -text'], attributes.rules.collect {|p| p.to_s}) end def test_add_text_rule dir = "#{working_dir}/#{::SecureRandom.hex}" attributes = Reality::Git::Attributes.new(dir) assert_equal([], attributes.rules.collect {|p| p.to_s}) attributes.text_rule('*.md') attributes.text_rule('*.rake', :eofnl => false) assert_equal(['*.md text', '*.rake text -eofnl'], attributes.rules.collect {|p| p.to_s}) end def test_add_unix_text_rule dir = "#{working_dir}/#{::SecureRandom.hex}" attributes = Reality::Git::Attributes.new(dir) assert_equal([], attributes.rules.collect {|p| p.to_s}) attributes.unix_text_rule('*.sh') attributes.unix_text_rule('*.init', :eofnl => false) assert_equal(['*.sh text eol=lf', '*.init text eol=lf -eofnl'], attributes.rules.collect {|p| p.to_s}) end def test_add_dos_text_rule dir = "#{working_dir}/#{::SecureRandom.hex}" attributes = Reality::Git::Attributes.new(dir) assert_equal([], attributes.rules.collect {|p| p.to_s}) attributes.dos_text_rule('*.cmd') attributes.dos_text_rule('*.rdl', :eofnl => false) assert_equal(['*.cmd text eol=crlf', '*.rdl text eol=crlf -eofnl'], attributes.rules.collect {|p| p.to_s}) end def test_add_binary_rule dir = "#{working_dir}/#{::SecureRandom.hex}" attributes = Reality::Git::Attributes.new(dir) assert_equal([], attributes.rules.collect {|p| p.to_s}) attributes.binary_rule('*.jpg') attributes.binary_rule('*.jpg', :category => 3) assert_equal(['*.jpg binary', '*.jpg binary category=3'], attributes.rules.collect {|p| p.to_s}) end def write_standard_file(dir, content) write_file("#{dir}/.gitattributes", content) end def write_file(attributes_file, content) FileUtils.mkdir_p File.dirname(attributes_file) IO.write(attributes_file, content) end end