/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to tests/test_commit.py

Merge sanitize commit message patch from John.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 John Arbash Meinel <john@arbash-meinel.com>
 
1
# Copyright (C) 2007, 2008 John Arbash Meinel <john@arbash-meinel.com>
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
644
644
                            'message':'message\nfor b_dir\n'},
645
645
                          ]), dlg._get_specific_files())
646
646
 
 
647
    def test_specific_files_sanitizes_messages(self):
 
648
        tree = self.make_branch_and_tree('tree')
 
649
        tree.branch.get_config().set_user_option('per_file_commits', 'true')
 
650
        self.build_tree(['tree/a_file', 'tree/b_dir/'])
 
651
        tree.add(['a_file', 'b_dir'], ['1a-id', '0b-id'])
 
652
 
 
653
        dlg = commit.CommitDialog(tree)
 
654
        dlg._commit_selected_radio.set_active(True)
 
655
        self.assertEqual((['a_file', 'b_dir'], []), dlg._get_specific_files())
 
656
 
 
657
        dlg._treeview_files.set_cursor((1,))
 
658
        dlg._set_file_commit_message('Test\r\nmessage\rfor a_file\n')
 
659
        dlg._treeview_files.set_cursor((2,))
 
660
        dlg._set_file_commit_message('message\r\nfor\nb_dir\r')
 
661
 
 
662
        self.assertEqual((['a_file', 'b_dir'],
 
663
                          [{'path':'a_file', 'file_id':'1a-id',
 
664
                            'message':'Test\nmessage\nfor a_file\n'},
 
665
                           {'path':'b_dir', 'file_id':'0b-id',
 
666
                            'message':'message\nfor\nb_dir\n'},
 
667
                          ]), dlg._get_specific_files())
 
668
 
647
669
 
648
670
class TestCommitDialog_Commit(tests.TestCaseWithTransport):
649
671
    """Tests on the actual 'commit' button being pushed."""
687
709
        self.assertEqual(last_rev, dlg.committed_revision_id)
688
710
        self.assertEqual(rev_id1, tree.branch.last_revision())
689
711
 
 
712
    def test_commit_global_sanitizes_message(self):
 
713
        tree = self.make_branch_and_tree('tree')
 
714
        self.build_tree(['tree/a'])
 
715
        tree.add(['a'], ['a-id'])
 
716
        rev_id1 = tree.commit('one')
 
717
 
 
718
        self.build_tree(['tree/b'])
 
719
        tree.add(['b'], ['b-id'])
 
720
        dlg = commit.CommitDialog(tree)
 
721
        # With the check box set, it should only effect the local branch
 
722
        dlg._set_global_commit_message('Commit\r\nmessage\rfoo\n')
 
723
        dlg._do_commit()
 
724
        rev = tree.branch.repository.get_revision(tree.last_revision())
 
725
        self.assertEqual('Commit\nmessage\nfoo\n', rev.message)
 
726
 
690
727
    def test_bound_commit_both(self):
691
728
        tree = self.make_branch_and_tree('tree')
692
729
        self.build_tree(['tree/a'])
1030
1067
                          {'path':u'\u03a9', 'file_id':'omega-id',
1031
1068
                           'message':u'\u03a9 is the end of all things.\n'},
1032
1069
                         ], file_info_decoded)
 
1070
 
 
1071
 
 
1072
class TestSanitizeMessage(tests.TestCase):
 
1073
 
 
1074
    def assertSanitize(self, expected, original):
 
1075
        self.assertEqual(expected,
 
1076
                         commit._sanitize_and_decode_message(original))
 
1077
 
 
1078
    def test_untouched(self):
 
1079
        self.assertSanitize('foo\nbar\nbaz\n', 'foo\nbar\nbaz\n')
 
1080
 
 
1081
    def test_converts_cr_to_lf(self):
 
1082
        self.assertSanitize('foo\nbar\nbaz\n', 'foo\rbar\rbaz\r')
 
1083
 
 
1084
    def test_converts_crlf_to_lf(self):
 
1085
        self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\r\nbaz\r\n')
 
1086
 
 
1087
    def test_converts_mixed_to_lf(self):
 
1088
        self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\rbaz\n')