# vim:ts=2:sw=2:et: #------------------------------------------------------------------------------- # Copyright (c) 1997-2008, Perforce Software, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE # SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. #------------------------------------------------------------------------------- class TC_Maps < Test::Unit::TestCase include P4RubyTest def name "Test mapping routines" end def test_maps client_map = P4::Map.new assert( client_map.class == P4::Map ) assert( client_map.empty? ) client_map.insert( "//depot/main/...", "//ws/main/..." ) assert_equal( client_map.count, 1 ) assert( !client_map.empty? ) client_map.insert( "//depot/live/...", "//ws/live/..." ) assert_equal( client_map.count, 2 ) client_map.insert( "//depot/bad/...", "//ws/live/bad/..." ) assert_equal( client_map.count, 4 ) # Basic translation p = client_map.translate( "//depot/main/foo/bar" ) assert_equal( p, "//ws/main/foo/bar" ) p = client_map.translate( "//ws/main/foo/bar", false ) assert_equal( p, "//depot/main/foo/bar" ) # Map joining. Create another map, and join it to the first ws_map = P4::Map.new( [ "//ws/... /home/user/ws/..." ] ) assert( !ws_map.empty? ) root_map = P4::Map.join( client_map, ws_map ) assert( !root_map.empty? ) # Now translate a depot path to a local path p = root_map.translate( "//depot/main/foo/bar" ) assert_equal( "/home/user/ws/main/foo/bar", p ) # Now reverse the mappings and try again root_map = root_map.reverse p = root_map.translate( "/home/user/ws/main/foo/bar" ) assert_equal( "//depot/main/foo/bar", p ) # Check space handling in mappings. Insert using both methods. With, # and without quotes. space_map = P4::Map.new space_map.insert( '"//depot/space dir1/..." "//ws/space 1/..."' ) space_map.insert( '"//depot/space dir2/..."', '"//ws/space 2/..."') space_map.insert( '//depot/space dir3/...', '//ws/space 3/...') # Test the results using translation. p = space_map.translate( "//depot/space dir1/foo" ) assert_equal( p, "//ws/space 1/foo" ) p = space_map.translate( "//depot/space dir2/foo" ) assert_equal( p, "//ws/space 2/foo" ) p = space_map.translate( "//depot/space dir3/foo" ) assert_equal( p, "//ws/space 3/foo" ) end end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 15524 | surajdolby |
Populate -o //guest/perforce_software/p4ruby/main/... //guest/surajdolby/p4ruby/.... |
||
//guest/perforce_software/p4ruby/main/test/11_maps_test.rb | |||||
#1 | 14676 | tony |
Rework P4Ruby unit tests so they they are actually units. Now the test order is irrelevant as all tests are standalone. Tidied up the code formatting as well and removed all the tabs from the ruby sources files. Added a modeline for vim users so consistent indentation will be used. |
||
//guest/perforce_software/p4ruby/main/test/11_maps.rb | |||||
#5 | 14610 | jmistry |
Fix unlink error on unit tests Wrap the connect/disconnect in begin/ensure blocks to ensure that the client disconnect even if there are failures in a unit test. Fix unicode unit test for 1.9. When the contents of a file is stored in a String object, ruby 1.9 sets the String's encoding to the current locale. This is overridden in the test case and set to the correct value. This may need to be documented. user visible change. |
||
#4 | 14553 | ateague |
Integrate change for Map::reverse bug fix where it used to change the map instead of returning a reversed copy of the map. Already in the release notes for 8.2. |
||
#3 | 14540 | tony |
Eliminate P4::Map.load() method, and make P4::Map.new() take an optional array of mappings instead. Taken from P4Python. Change to unreleased new feature |
||
#2 | 14538 | tony |
Fix quoting bug in P4::Map code. Quotes should not be passed down to the MapApi layer - they just need to be respected in order to identify the left- and right-hand sides of the mappings. Includes some tests to check the handling of mappings with embedded spaces and quotes. Bug fix to unreleased functionality |
||
#1 | 14534 | tony |
Add support for the MapApi class in P4Ruby. This change adds a new class, P4::Map, to P4Ruby's canon. The methods on P4::Map are: P4::Map.new - Constructor P4::Map.load - Load a map from an array P4::Map.join - Join two maps to create a third P4::Map#clear - Empty a map P4::Map#count - Return the number of entries P4::Map#empty? - Tests whether a map object is empty P4::Map#translate - Translate a string through a map P4::Map#includes? - Tests whether a path is mapped P4::Map#lhs - Returns the left side as an array P4::Map#rhs - Returns the right side as an array P4::Map#to_a - Returns the map as an array (Note, the first three are class methods, the rest instance methods) There is also P4::Map#reverse(), but I'm not documenting that yet as I'm not sure I understand the semantics of reversing complex maps well enough. User-visible enhancement documented in p4rubynotes.txt and slated for 2008.2 release. |