<s> import unittest <EOL> import json <EOL> import re <EOL> import os <EOL> import sys <EOL> parent_dir = os . path . dirname ( os . path . dirname ( os . path . abspath ( __file__ ) ) ) <EOL> sys . path . insert ( <NUM_LIT:1> , parent_dir ) <EOL> sys . path . insert ( <NUM_LIT:1> , parent_dir + "<STR_LIT:\\>" + "<STR_LIT>" ) <EOL> import projectsystem <EOL> from projectsystem import Sourcemap <EOL> assets_path = os . path . abspath ( "<STR_LIT>" + os . path . sep + "<STR_LIT>" ) . lower ( ) + os . path . sep <EOL> class SourceMapParserTests ( unittest . TestCase ) : <EOL> map_version_2 = '<STR_LIT>' <EOL> map_version_3 = '<STR_LIT>' <EOL> def test_nonexistent_file_does_not_throw ( self ) : <EOL> file_name = Sourcemap . get_sourcemap_file ( "<STR_LIT>" ) <EOL> self . assertFalse ( file_name ) <EOL> def test_valid_json_invalid_map_does_not_throw ( self ) : <EOL> file_name = Sourcemap . get_sourcemap_file ( "<STR_LIT>" ) <EOL> self . assertFalse ( file_name ) <EOL> def test_version_check ( self ) : <EOL> line_mappings = Sourcemap . SourceMapParser . calculate_line_mappings ( json . loads ( self . map_version_2 ) ) <EOL> self . assertFalse ( line_mappings ) <EOL> line_mappings = Sourcemap . SourceMapParser . calculate_line_mappings ( json . loads ( self . map_version_3 ) ) <EOL> self . assertTrue ( line_mappings ) <EOL> def test_line_mapping_count ( self ) : <EOL> content = json . loads ( self . map_version_3 ) <EOL> line_mappings = Sourcemap . SourceMapParser . calculate_line_mappings ( content ) <EOL> self . assertEqual ( len ( line_mappings ) , len ( re . split ( '<STR_LIT>' , content [ "<STR_LIT>" ] ) ) ) <EOL> class ParsedSourceMapTests ( unittest . TestCase ) : <EOL> def test_invalid_file_does_not_throw ( self ) : <EOL> parsed_map = Sourcemap . ParsedSourceMap ( "<STR_LIT>" ) <EOL> self . assertFalse ( parsed_map . is_valid ( ) ) <EOL> self . assertFalse ( parsed_map . content ) <EOL> def test_valid_json_invalid_map_does_not_throw ( self ) : <EOL> parsed_map = Sourcemap . ParsedSourceMap ( assets_path + "<STR_LIT>" ) <EOL> self . assertFalse ( parsed_map . is_valid ( ) ) <EOL> def test_invalid_file_returns_empty_authored_list ( self ) : <EOL> parsed_map = Sourcemap . ParsedSourceMap ( "<STR_LIT>" ) <EOL> self . assertFalse ( parsed_map . is_valid ( ) ) <EOL> self . assertEqual ( len ( parsed_map . get_authored_sources_path ( ) ) , <NUM_LIT:0> ) <EOL> def test_valid_map_file_parsing ( self ) : <EOL> parsed_map = Sourcemap . ParsedSourceMap ( assets_path + "<STR_LIT>" ) <EOL> self . assertTrue ( parsed_map . is_valid ( ) ) <EOL> self . assertTrue ( parsed_map . content ) <EOL> def test_valid_map_authored_list ( self ) : <EOL> parsed_map = Sourcemap . ParsedSourceMap ( assets_path + "<STR_LIT>" ) <EOL> self . assertTrue ( parsed_map . is_valid ( ) ) <EOL> self . assertEqual ( parsed_map . version , <NUM_LIT:3> ) <EOL> self . assertEqual ( len ( parsed_map . get_authored_sources_path ( ) ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( parsed_map . get_authored_sources_path ( ) , [ assets_path + "<STR_LIT>" ] ) <EOL> class LineMappingsTests ( unittest . TestCase ) : <EOL> def test_empty_mappings ( self ) : <EOL> self . assertFalse ( Sourcemap . LineMapping . binary_search ( [ ] , <NUM_LIT:0> , <NUM_LIT:0> , Sourcemap . LineMapping . compare_source_mappings ) ) <EOL> self . assertFalse ( Sourcemap . LineMapping . binary_search ( [ ] , <NUM_LIT:0> , <NUM_LIT:0> , Sourcemap . LineMapping . compare_generated_mappings ) ) <EOL> def test_binary_search_source_mappings ( self ) : <EOL> parsed_map = Sourcemap . ParsedSourceMap ( assets_path + "<STR_LIT>" ) <EOL> result = Sourcemap . LineMapping . binary_search ( parsed_map . line_mappings , <NUM_LIT:10> , <NUM_LIT:16> , Sourcemap . LineMapping . compare_source_mappings ) <EOL> self . assertTrue ( result , <NUM_LIT:16> ) <EOL> mapping = parsed_map . line_mappings [ result ] <EOL> self . assertEqual ( mapping . generated_line , <NUM_LIT:5> ) <EOL> self . assertEqual ( mapping . generated_column , <NUM_LIT:16> ) <EOL> def test_binary_search_generated_mappings ( self ) : <EOL> parsed_map = Sourcemap . ParsedSourceMap ( assets_path + "<STR_LIT>" ) <EOL> result = Sourcemap . LineMapping . binary_search ( parsed_map . line_mappings , <NUM_LIT:5> , <NUM_LIT:16> , Sourcemap . LineMapping . compare_generated_mappings ) <EOL> self . assertTrue ( result , <NUM_LIT:16> ) <EOL> mapping = parsed_map . line_mappings [ result ] <EOL> self . assertEqual ( mapping . source_line , <NUM_LIT:10> ) <EOL> self . assertEqual ( mapping . source_column , <NUM_LIT:16> ) <EOL> def test_binary_search_not_existent_source_mappings ( self ) : <EOL> parsed_map = Sourcemap . ParsedSourceMap ( assets_path + "<STR_LIT>" ) <EOL> result = Sourcemap . LineMapping . binary_search ( parsed_map . line_mappings , <NUM_LIT:100> , <NUM_LIT:1000> , Sourcemap . LineMapping . compare_source_mappings ) <EOL> self . assertTrue ( result , len ( parsed_map . line_mappings ) ) <EOL> mapping = parsed_map . line_mappings [ result ] <EOL> self . assertEqual ( mapping . generated_line , <NUM_LIT> ) <EOL> self . assertEqual ( mapping . generated_column , <NUM_LIT:2> ) <EOL> def test_binary_search_not_existent_generated_mappings ( self ) : <EOL> parsed_map = Sourcemap . ParsedSourceMap ( assets_path + "<STR_LIT>" ) <EOL> result = Sourcemap . LineMapping . binary_search ( parsed_map . line_mappings , <NUM_LIT:100> , <NUM_LIT:1000> , Sourcemap . LineMapping . compare_generated_mappings ) <EOL> self . assertTrue ( result , len ( parsed_map . line_mappings ) ) <EOL> mapping = parsed_map . line_mappings [ result ] <EOL> self . assertEqual ( mapping . source_line , <NUM_LIT> ) <EOL> self . assertEqual ( mapping . source_column , <NUM_LIT:2> ) </s>
