|
3 | 3 | describe 'document_validator' do |
4 | 4 | let(:subject) { PuppetLanguageServer::DocumentValidator } |
5 | 5 |
|
| 6 | + describe '#fix_validate_errors' do |
| 7 | + describe "Given an incomplete manifest which has syntax errors but no lint errors" do |
| 8 | + let(:manifest) { 'user { \'Bob\'' } |
| 9 | + |
| 10 | + it "should return no changes" do |
| 11 | + problems_fixed, new_content = subject.fix_validate_errors(manifest, nil) |
| 12 | + expect(problems_fixed).to eq(0) |
| 13 | + expect(new_content).to eq(manifest) |
| 14 | + end |
| 15 | + end |
| 16 | + |
| 17 | + describe "Given a complete manifest which has a single fixable lint errors" do |
| 18 | + let(:manifest) { " |
| 19 | + user { \"Bob\": |
| 20 | + ensure => 'present' |
| 21 | + }" |
| 22 | + } |
| 23 | + let(:new_manifest) { " |
| 24 | + user { 'Bob': |
| 25 | + ensure => 'present' |
| 26 | + }" |
| 27 | + } |
| 28 | + |
| 29 | + it "should return changes" do |
| 30 | + problems_fixed, new_content = subject.fix_validate_errors(manifest, nil) |
| 31 | + expect(problems_fixed).to eq(1) |
| 32 | + expect(new_content).to eq(new_manifest) |
| 33 | + end |
| 34 | + end |
| 35 | + |
| 36 | + describe "Given a complete manifest which has multiple fixable lint errors" do |
| 37 | + let(:manifest) { " |
| 38 | + // bad comment |
| 39 | + user { \"Bob\": |
| 40 | + name => 'username', |
| 41 | + ensure => 'present' |
| 42 | + }" |
| 43 | + } |
| 44 | + let(:new_manifest) { " |
| 45 | + # bad comment |
| 46 | + user { 'Bob': |
| 47 | + name => 'username', |
| 48 | + ensure => 'present' |
| 49 | + }" |
| 50 | + } |
| 51 | + |
| 52 | + it "should return changes" do |
| 53 | + problems_fixed, new_content = subject.fix_validate_errors(manifest, nil) |
| 54 | + expect(problems_fixed).to eq(3) |
| 55 | + expect(new_content).to eq(new_manifest) |
| 56 | + end |
| 57 | + end |
| 58 | + |
| 59 | + |
| 60 | + describe "Given a complete manifest which has unfixable lint errors" do |
| 61 | + let(:manifest) { " |
| 62 | + user { 'Bob': |
| 63 | + name => 'name', |
| 64 | + ensure => 'present' |
| 65 | + }" |
| 66 | + } |
| 67 | + |
| 68 | + it "should return no changes" do |
| 69 | + problems_fixed, new_content = subject.fix_validate_errors(manifest, nil) |
| 70 | + expect(problems_fixed).to eq(0) |
| 71 | + expect(new_content).to eq(manifest) |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + describe "Given a complete manifest with CRLF which has fixable lint errors" do |
| 76 | + let(:manifest) { "user { \"Bob\":\r\nensure => 'present'\r\n}" } |
| 77 | + let(:new_manifest) { "user { 'Bob':\r\nensure => 'present'\r\n}" } |
| 78 | + |
| 79 | + it "should preserve CRLF" do |
| 80 | + pending('Release of https://github.com/rodjek/puppet-lint/commit/2a850ab3fd3694a4dd0c4d2f22a1e60b9ca0a495') |
| 81 | + problems_fixed, new_content = subject.fix_validate_errors(manifest, nil) |
| 82 | + expect(problems_fixed).to eq(1) |
| 83 | + expect(new_content).to eq(new_manifest) |
| 84 | + end |
| 85 | + end |
| 86 | + |
| 87 | + describe "Given a complete manifest which has disabed fixable lint errors" do |
| 88 | + let(:manifest) { " |
| 89 | + user { \"Bob\": # lint:ignore:double_quoted_strings |
| 90 | + ensure => 'present' |
| 91 | + }" |
| 92 | + } |
| 93 | + |
| 94 | + it "should return no changes" do |
| 95 | + problems_fixed, new_content = subject.fix_validate_errors(manifest, nil) |
| 96 | + expect(problems_fixed).to eq(0) |
| 97 | + expect(new_content).to eq(manifest) |
| 98 | + end |
| 99 | + end |
| 100 | + end |
| 101 | + |
6 | 102 | describe '#validate' do |
7 | 103 | describe "Given an incomplete manifest which has syntax errors" do |
8 | 104 | let(:manifest) { 'user { "Bob"' } |
|
0 commit comments