From da9bda0e27966df638e3465b6e0383db2d1d336b Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Sun, 19 Apr 2015 16:19:52 +0200 Subject: [PATCH] Detect KiCAD module files as generated --- lib/linguist/generated.rb | 16 +++++++++- test/fixtures/Generated/ABM8G.mod | 50 +++++++++++++++++++++++++++++++ test/test_blob.rb | 5 ++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/Generated/ABM8G.mod diff --git a/lib/linguist/generated.rb b/lib/linguist/generated.rb index 12987196..88226954 100644 --- a/lib/linguist/generated.rb +++ b/lib/linguist/generated.rb @@ -68,7 +68,8 @@ module Linguist generated_protocol_buffer_go? || generated_protocol_buffer? || generated_jni_header? || - vcr_cassette? + vcr_cassette? || + generated_kicad_module? end # Internal: Is the blob an Xcode file? @@ -311,5 +312,18 @@ module Linguist return false unless lines.count > 1 return lines[0].include?("Generated by Cython") end + + # Internal: Is it a KiCAD module file? + # + # KiCAD module files contain: + # PCBNEW-LibModule-V1 yyyy-mm-dd h:mm:ss XM + # on the first line. + # + # Return true of false + def generated_kicad_module? + return false unless extname == '.mod' + return false unless lines.count > 1 + return lines[0].include?("PCBNEW-LibModule-V") + end end end diff --git a/test/fixtures/Generated/ABM8G.mod b/test/fixtures/Generated/ABM8G.mod new file mode 100644 index 00000000..15887130 --- /dev/null +++ b/test/fixtures/Generated/ABM8G.mod @@ -0,0 +1,50 @@ +PCBNEW-LibModule-V1 Wed 10 Aug 2011 05:57:27 PM COT +# encoding utf-8 +$INDEX +ABM8G +$EndINDEX +$MODULE ABM8G +Po 0 0 0 15 4E430CBD 4E430CC5 ~~ +Li ABM8G +Sc 4E430CC5 +AR +Op 0 0 0 +T0 591 -1378 354 354 0 39 N V 21 N "ABM8G" +T1 0 787 354 354 0 39 N V 21 N "VAL**" +DS -591 394 1299 394 79 21 +DS 1299 394 1299 -1063 79 21 +DS 1299 -1063 -472 -1063 79 21 +DS -472 -1063 -472 472 79 21 +DS -472 472 -472 551 79 21 +DS -472 551 -591 551 79 21 +DS -591 551 -591 433 79 21 +$PAD +Sh "1" R 551 472 0 0 0 +Dr 0 0 0 +At SMD N 00888000 +Ne 0 "" +Po 0 0 +$EndPAD +$PAD +Sh "2" R 551 472 0 0 0 +Dr 0 0 0 +At SMD N 00888000 +Ne 0 "" +Po 866 0 +$EndPAD +$PAD +Sh "3" R 551 472 0 0 0 +Dr 0 0 0 +At SMD N 00888000 +Ne 0 "" +Po 866 -669 +$EndPAD +$PAD +Sh "4" R 551 472 0 0 0 +Dr 0 0 0 +At SMD N 00888000 +Ne 0 "" +Po 0 -669 +$EndPAD +$EndMODULE ABM8G +$EndLIBRARY diff --git a/test/test_blob.rb b/test/test_blob.rb index 138eef8e..88d4c795 100644 --- a/test/test_blob.rb +++ b/test/test_blob.rb @@ -243,6 +243,9 @@ class TestBlob < Minitest::Test # Cython-generated C/C++ assert sample_blob("C/sgd_fast.c").generated? assert sample_blob("C++/wrapper_inner.cpp").generated? + + # KiCAD module files + assert fixture_blob("Generated/ABM8G.mod").generated? end def test_vendored @@ -536,6 +539,8 @@ class TestBlob < Minitest::Test blob = fixture_blob(filepath) if language == 'Data' assert blob.language.nil?, "A language was found for #{filepath}" + elsif language == 'Generated' + assert blob.generated?, "#{filepath} is not a generated file" else assert blob.language, "No language for #{filepath}" assert_equal language, blob.language.name, blob.name