class CachedNestedFileReaderTest

def setup

def setup
  @file2 = Tempfile.new('test2.txt')
  @file2.write("ImportedLine1\nImportedLine2")
  @file2.rewind
  @file1 = Tempfile.new('test1.txt')
  @file1.write("Line1\nLine2\n #insert #{@file2.path}\nLine3")
  @file1.rewind
  @reader = CachedNestedFileReader.new(import_pattern: /^ *#insert (?'name'.+)$/)
end

def teardown

def teardown
  @file1.close
  @file1.unlink
  @file2.close
  @file2.unlink
end

def test_caching_functionality

def test_caching_functionality
  # First read
  result1 = @reader.readlines(@file2.path).map(&:to_s)
  # Simulate file content change
  @file2.reopen(@file2.path, 'w') { |f| f.write('ChangedLine') }
  # Second read (should read from cache, not the changed file)
  result2 = @reader.readlines(@file2.path).map(&:to_s)
  assert_equal result1, result2
  assert_equal %w[ImportedLine1 ImportedLine2], result2
end

def test_readlines_with_imports

def test_readlines_with_imports
  result = @reader.readlines(@file1.path).map(&:to_s)
  assert_equal %w[Line1 Line2 ImportedLine1 ImportedLine2 Line3],
               result
end

def test_readlines_without_imports

def test_readlines_without_imports
  result = @reader.readlines(@file2.path).map(&:to_s)
  assert_equal %w[ImportedLine1 ImportedLine2], result
end