diff --git a/lib/gollum/file_view.rb b/lib/gollum/file_view.rb index 86895399..624b991d 100644 --- a/lib/gollum/file_view.rb +++ b/lib/gollum/file_view.rb @@ -10,7 +10,7 @@ module Gollum end def enclose_tree string - %Q(
    \n) + string + %Q(\n
) + %Q(
    \n) + string + %Q(
) end def new_page page diff --git a/test/file_view/1_file.txt b/test/file_view/1_file.txt new file mode 100644 index 00000000..6f65a3a3 --- /dev/null +++ b/test/file_view/1_file.txt @@ -0,0 +1,3 @@ +
    +
  1. 0
  2. +
\ No newline at end of file diff --git a/test/file_view/1_file_1_folder.txt b/test/file_view/1_file_1_folder.txt new file mode 100644 index 00000000..ead7f704 --- /dev/null +++ b/test/file_view/1_file_1_folder.txt @@ -0,0 +1,8 @@ +
    +
  1. + +
      +
    1. 0
    2. +
    +
  2. +
\ No newline at end of file diff --git a/test/file_view/1_folder.txt b/test/file_view/1_folder.txt new file mode 100644 index 00000000..f960bee7 --- /dev/null +++ b/test/file_view/1_folder.txt @@ -0,0 +1,8 @@ +
    +
  1. + +
      +
    1. folder0
    2. +
    +
  2. +
\ No newline at end of file diff --git a/test/file_view/2_files_2_folders.txt b/test/file_view/2_files_2_folders.txt new file mode 100644 index 00000000..11da79d0 --- /dev/null +++ b/test/file_view/2_files_2_folders.txt @@ -0,0 +1,12 @@ +
    +
  1. + +
      +
    1. 0
    2. +
    +
  2. +
  3. + +
      +
    1. 1
    2. +
    \ No newline at end of file diff --git a/test/file_view/2_files_2_folders_1_root.txt b/test/file_view/2_files_2_folders_1_root.txt new file mode 100644 index 00000000..7c1e4a96 --- /dev/null +++ b/test/file_view/2_files_2_folders_1_root.txt @@ -0,0 +1,13 @@ +
      +
    1. root
    2. +
    3. + +
        +
      1. 0
      2. +
      +
    4. +
    5. + +
        +
      1. 1
      2. +
      \ No newline at end of file diff --git a/test/file_view/nested_folders.txt b/test/file_view/nested_folders.txt new file mode 100644 index 00000000..5daae668 --- /dev/null +++ b/test/file_view/nested_folders.txt @@ -0,0 +1,18 @@ +
        +
      1. + +
          +
        1. 0
        2. +
        3. + +
            +
          1. 1
          2. +
          +
        4. +
        +
      2. +
      3. + +
          +
        1. 2
        2. +
        \ No newline at end of file diff --git a/test/test_file_view.rb b/test/test_file_view.rb new file mode 100644 index 00000000..12e89852 --- /dev/null +++ b/test/test_file_view.rb @@ -0,0 +1,107 @@ +# ~*~ encoding: utf-8 ~*~ +require File.expand_path(File.join(File.dirname(__FILE__), 'helper')) +require File.expand_path '../../lib/gollum/file_view', __FILE__ + +class FakePage + def initialize filepath + @filepath = filepath + end + + def path + return @filepath + end + + # From page.rb + def name + self.class.canonicalize_filename @filepath + end + + # From page.rb + def self.strip_filename filename + ::File.basename( filename, ::File.extname( filename )) + end + + # From page.rb + def self.canonicalize_filename filename + strip_filename(filename).gsub('-', ' ') + end +end + +class FakePages + def initialize filepath_array + @array = filepath_array.map { | filepath | FakePage.new filepath } + end + + def size + @array.size + end + + def [] index + @array[ index ] + end +end + +def view pages + Gollum::FileView.new( pages ).render_files +end + +@@test_path = File.expand_path( '../file_view/' , __FILE__ ) + '/' + +def read file + File.read @@test_path + file + '.txt' +end + +# For creating expected files. +def write file, content + File.open(@@test_path + file + '.txt', 'w') do | f | + f.write content + end +end + +# Test Notes +# root files must be before any folders. +# Home.md => file at root folder +# docs/sanitization.md => file within folder +context 'file_view' do + test 'one file' do + pages = FakePages.new [ '0.md' ] + expected = read '1_file' + actual = view pages + assert_equal expected, actual + end + + test 'one folder' do + pages = FakePages.new [ 'folder0/' ] + expected = read '1_folder' + actual = view pages + assert_equal expected, actual + end + + test 'one file with one folder' do + pages = FakePages.new [ 'folder0/0.md' ] + expected = read '1_file_1_folder' + actual = view pages + assert_equal expected, actual + end + + test 'two files with two folders' do + pages = FakePages.new [ 'folder0/0.md', 'folder1/1.md' ] + expected = read '2_files_2_folders' + actual = view pages + assert_equal expected, actual + end + + test 'two files with two folders and one root file' do + pages = FakePages.new [ 'root.md', 'folder0/0.md', 'folder1/1.md' ] + expected = read '2_files_2_folders_1_root' + actual = view pages + assert_equal expected, actual + end + + test 'nested folders' do + pages = FakePages.new [ 'folder0/folder1/folder2/0.md', 'folder0/folder1/folder3/1.md', 'folder4/2.md' ] + expected = read 'nested_folders' + actual = view pages + assert_equal expected, actual + end +end # context