summaryrefslogtreecommitdiff
path: root/biblio/bibtex/utils/bibtexperllibs/BibTeX-Parser/t/03-parse_entry.t
blob: 6b4e4632bccdfda1a0dc35e3e731d5b968bf0e50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/perl -w

use Test::More tests => 3;

use IO::String;
use BibTeX::Parser;

{
    my $string = q|@article{lin1973,
       author = "Shen Lin and Brian W. Kernighan",
       title = "An Effective Heuristic Algorithm for the Travelling-Salesman Problem",
       journal = "Operations Research",
       volume = 21,
       year = 1973,
       pages = "498--516"
    }|;
    my $fh = IO::String->new($string);

    my $parser = BibTeX::Parser->new( $fh );

#my @result = BibTeX::Parser->_parse($fh);

    my $entry = $parser->next;

    is_deeply($entry, {_type => 'ARTICLE', _key => 'lin1973', author => "Shen Lin and Brian W. Kernighan",
       title => "An Effective Heuristic Algorithm for the Travelling-Salesman Problem",
       journal => "Operations Research",
       volume => 21,
       year => 1973,
       pages => "498--516", _parse_ok => 1,
       _fieldnums =>   {'author' => 0, 'title' => 1,
                        'journal' => 2, 'volume' => 3,
			    'year' => 4, 'pages' => 5},
       _pre => '',		       
       _raw => $string}, "parse \@ARTICLE");

}
{
    my $string1 = q|@article{lin1973,
       author = "Shen Lin and Brian W. Kernighan",
       title = "An Effective Heuristic Algorithm for the Travelling-Salesman Problem",
       journal = "Operations Research",
       volume = 21,
       year = 1973,
       pages = "498--516"
    }|;
    my $string = "some
text
$string1";
    my $fh = IO::String->new($string);

    my $parser = BibTeX::Parser->new( $fh );

#my @result = BibTeX::Parser->_parse($fh);

    my $entry = $parser->next;

    is_deeply($entry, {_type => 'ARTICLE', _key => 'lin1973', author => "Shen Lin and Brian W. Kernighan",
       title => "An Effective Heuristic Algorithm for the Travelling-Salesman Problem",
       journal => "Operations Research",
       volume => 21,
       year => 1973,
       pages => "498--516", _parse_ok => 1,
       _fieldnums =>   {'author' => 0, 'title' => 1,
                        'journal' => 2, 'volume' => 3,
			    'year' => 4, 'pages' => 5},
       _pre => "some\ntext",		       
       _raw => $string1}, "parse \@ARTICLE");

}
{
    my $string = q|@InProceedings{Herper:2001:MVS,
  author = 	 {Henry Herper},
  title = 	 {{M}odellierung von {S}ystemen: ein
		  {A}pplikationsgebiet im {I}nformatikunterricht},
  booktitle = 	 {Informatikunterricht und Medienbildung, INFOS 2001
		  (9. Fachtagung Informatik und Schule, Paderborn
		  17.-20- September 2001) -- Tagungsband},
  editor =	 {Reinhard Keil-Slavik and Johannes Magenheim},
  year =	 {2001},
}|;
    my $fh = IO::String->new($string);

    my $parser = BibTeX::Parser->new( $fh );

    my $entry = $parser->next;

    is_deeply($entry, {
        _type => 'INPROCEEDINGS',
        _key => 'Herper:2001:MVS',
       _fieldnums =>   {'author' => 0, 'title' => 1,
                        'booktitle' => 2, 'editor' => 3,
                        'year' => 4},
        author => "Henry Herper",
        title => "{M}odellierung von {S}ystemen: ein {A}pplikationsgebiet im {I}nformatikunterricht",
        booktitle => "Informatikunterricht und Medienbildung, INFOS 2001 (9. Fachtagung Informatik und Schule, Paderborn 17.-20- September 2001) -- Tagungsband",
        editor => "Reinhard Keil-Slavik and Johannes Magenheim",
        year => 2001,
        _parse_ok => 1,
        _pre => '',
        _raw => $string}, "parse \@ARTICLE");
}